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. please guide me to get the jar path. Or suggest me the best way to build SessionFactory and bind the same to a JNDI name.
I don't think this issue is specific to Hibernate, so if there is a Hibernate issue here also, I could be off-base.
You don't need a path to the Jar file. The Jar file just needs to be on the class loader for the component that is trying to access it. I believe there is a FAQ entry that talks about how the class loaders are set up for various components within a JEE application, but basically, if you place a Jar file in the 'lib' directory of the Ear, it will be on the Ear class loader, which will be used as the parent for the EJB and Web application class loaders.
Once the Jar is on the class path, then the resources within the Jar (files, classes, etc.) will be accessible to the application in the normal way.
Mark as you suggest I have added Persistence.jar in EAR lib to make it's classes and files available to all it's components. But I am unable to build session factory. I am getting the following exception
this hibernate.cfg.xml there in conf dir of Persistance.jar
Can you guide me with few more tips?
or please post the links which will discuss more about class loaders on JEE applications
I'm not really a hibernate person, so if there are some hibernate-special rules, I may not be aware of them.
In looking at your image, that's not your Jar structure, that the layout of the sources for your PERSISTENCE project in your IDE. Are you sure you're even creating a Persistence.jar file? What does it look like?
If you have to, execute jar -tvf Persistence.jar and see what that shows.
Mark E Hansen wrote:I'm not really a hibernate person, so if there are some hibernate-special rules, I may not be aware of them.
In looking at your image, that's not your Jar structure, that the layout of the sources for your PERSISTENCE project in your IDE. Are you sure you're even creating a Persistence.jar file? What does it look like?
If you have to, execute jar -tvf Persistence.jar and see what that shows.
Problem solved Mark. Thank you very much for your time. Thanks a lot.