Walter
Walter

Reputation: 1470

Hibernate with Spring

I am having some problems getting Hibernate and Spring up and running. I have a web server project which makes use of several other projects which have persistent entities in them. The problem I have is that I get a ClassNotFoundException for an entity class that is stored within another jar inside of WEB-INF/libs.

Do I need to have a persistence.xml for each jar that contains entity classes?

Please let me know if you need to see any configuration files.

Upvotes: 1

Views: 134

Answers (1)

Shriram Shrikumar
Shriram Shrikumar

Reputation: 1155

Depending on your set up there are probably a number of different ways to solve this - and none them usually feel idea (IMO).

The essential problem is to do with ClassLoader isolation. There are rules as to what the files within a jar can access.

In your particular case, the easiest way to solve it is probably to put the persistence.xml within the parent web project. If you are not using persistence xml, you need to bootstrap hibernate/spring from the web project.

The parent web project should have access to all the libraries within its WEB-INF/lib whereas each of the jars in the libs folder may not have access to each other.

You could set up another persistence.xml in each jar but they would not be composited together into one persistence unit. You would need to use a different pu depending on which entity you wanted.

Upvotes: 1

Related Questions