• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using hibernate in J2EE app

 
naresh pokuri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Naresh, Can you explain solution for the issue ?
 
naresh pokuri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic