Distributing a persistance class that uses Hibernate - java

So I have a standalone application and a web application to do, but the persistance classes that I've created in the standalone gonna be used in the web application too.
Since my standalone project have the hibernate.cfg.xml and the hbm.xml for each persistance class, how can I export this project like in a JAR and just import in the web application project and use the classes easily?

Use maven to create a jar containing persistence classes and *.hbm.xml files. In your webapp you can use this jar as a dependency and use the hbm files to configure your session factory bean.

Related

test folder configuration in web project

I have a spring web project in eclipse which has folder structure as
src/main/java
src/main/resources
src/test/java
src/test/resources
For some time my eclipse project used to work fine. But recently, when i start the application my eclipse project loads spring annotated beans from
src/test/java
folder.Because of this i am getting
org.springframework.beans.factory.NoUniqueBeanDefinitionException
from spring as there are two implementations of the same spring bean.
When i remove this folder from build path my application works well. Can someone please help with the reason for such behavioral change in my project?
we have two types of ioc containers in spring BeanFactory,ApplicationContext.when a request comes bean factory creates the instance which we declare a bean in xml. but application context creates all bean instances at the time of loading....

Java Injection from one war file to another

I started developing project where weblogic is used as webserver. In this project, we have several war files merged into one ear file. Now, I need some functionality (dao access) from one war file in another waqr file. Is it possible to use EJB or java Injection to get an instance of dao object from one war fle in second war file?
The easiest way to do this is to move the dao access classes up into the EAR file where both web modules will have visibility of the classes.
Individual web modules (war files) each get their own class loader and are unable to see each other's classes.

How to use persistence unit defined in extern library?

In a project (war), I am using an EntityManager defined using a persistence unit. The definition of this persistence unit is made in a library that is packed as jar and installed on in Glassfish's libs. This lib is not included in the war.
Since I am using the persistence-unit defined in the library's persistence.xml, I have to copy it into my project.
I prefer not having to do this.
Is there a way, such that I don't need to copy this persistence.xml and just reference it somehow in the library or anything like that?

Add shared project jars in websphere shared library

We can add project dependency jars (like spring jars, logging etc) in shared library, can we add shared project jars (like one that communicate with Database) in shared library?
Scenario:
I have these projects
WebApp
WebAppEAR
CommonDB
I am using IBM Websphere server, hibernate, spring mvc
I added all spring, hibernate jars including CommonDB.jar in Websphere shared library. WebApp Application is running successfully with spring controllers but when my application try to hit DB it throws exception.
Caused by: java.lang.IllegalStateException:
Actually WebApp is not loading <bean> DataSource. DataSource class is located in CommonDB project.
When I include CommonDB.jar in Deployment assembly of EAR WebApp runs successfully and fetches data from DB.
I want to exclude CommonDB.jar from Deployment assembly and only want to add it in shared library.
Adding jars in shared library will work. Try figuring out which beans are not initialized and add them in Spring file to initialize. Also check other bean properties for dependency.

Using hibernate in Java EE app

I am maintaining following structure for my project
Web - Web Project
Model - EJB Project
Persistence - Java project having data classes and their mapping for Hibernate
Pokuri - EAR Project
As we know we can give jar file to hibernate configuration to load mapping information from jar. As I deploy EAR on to server I just want to build SessionFactory from mapping files in Persistence jar. But I am unable to get the path for that jar. Plz guide me to get the jar path. Or suggest me the best way to build SessionFactory and bind the same to a JNDI name.
Take a look at this thread - it may contain useful information.
Also, make sure your jar is mapped in your application.xml as an ejb module.

Categories

Resources