wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes using hibernate in J2EE app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "using hibernate in J2EE app" Watch "using hibernate in J2EE app" New topic
Author

using hibernate in J2EE app

naresh pokuri
Greenhorn

Joined: Feb 13, 2010
Posts: 10

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. 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.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
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.

I hope this helps,
naresh pokuri
Greenhorn

Joined: Feb 13, 2010
Posts: 10
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
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Here's an article on classloading. If this is not enough, Google should help too:
http://www.technicalfacilitation.com/get.php?link=classloading

I would think what you did would put the file on the classpath, so perhaps something else is wrong?
naresh pokuri
Greenhorn

Joined: Feb 13, 2010
Posts: 10
Mark E Hansen wrote:Here's an article on classloading. If this is not enough, Google should help too:
http://www.technicalfacilitation.com/get.php?link=classloading

I would think what you did would put the file on the classpath, so perhaps something else is wrong?


Thank you Mark. That was a very useful link. I gone through that completely.

Still I am getting the same exception

Here is my Persistance.jar structure


and my code to build SessionFactory in a local SessionBean exist in Model component of POKURI EAR. the code is


can you please help me that how can I build my SessionFactory

Thanks for your time
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
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.

naresh pokuri
Greenhorn

Joined: Feb 13, 2010
Posts: 10
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.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
Hi Naresh, Can you explain solution for the issue ?
naresh pokuri
Greenhorn

Joined: Feb 13, 2010
Posts: 10
kri shan wrote:Hi Naresh, Can you explain solution for the issue ?


Just go through the article on classloader(link provided by mark in this post)

What I did is as mark told I have added the conf folder as class folder.

Then I write following statement in a Bean method as follows



if you observe ClassLoader API, there are few methods that can help you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using hibernate in J2EE app
 
Similar Threads
hibernate with HSQL db - Acquisition Attempt Failed Error
NoClassDefFoundError:
WSAD 5.0 - Class path
Exception on Startup
jars within jars