Hello,
I am doing a Spring application using JPA. I am using Hibernate Entity Manager as JPA provider. From my pom.xml:
Code:
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
Here is my DAO class (annotated with the appropriate Spring annotation to make sure transaction is started):
Code:
@Transactional
public UnweTest persistTest(UnweTest unweTest) {
entityManager.persist(unweTest);
return unweTest;
}
Unfortunately when calling it from a unit test it does not do an insert into the database. Initially I thought that the problem is in the way I configure this transactional stuff. But I double/triple checked it with a couple of my other projects as well as with some threads on Stack Overflow. After I assured (or at least I think so) that everything in my code is set up as it should be, I downloaded the Hibernate Entity Manager source code and started a debugger to find out what is going wrong.
So I reached the persist(Object entity) method in the AbstractEntityManager class with my debugger. It calls:
Code:
getSession().persist( entity );
Which brings the execution in the org.hibernate.impl.SessionImpl class. This is part of the Hibernate core jar. It was not described explicitly in my pom.xml, but Maven has brought it somehow. And then what persist does is:
Code:
firePersist( new PersistEvent(entityName, object, this) );
And finally, when it tries to instantiate the PersistEvent, I get ClassNotFoundException for this class org.hibernate.event.PersistEvent. Here I wonder three things:
1) Why is ClassNotFoundException thrown as I don't see any Class.forName or the other means of dynamically loading classes. It is doing new PersistEvent
2) The exception is somehow swollen: when I went on with the debugger, I finally reached back the persist method in the SessionImpl, which silently exited and traced back
3) Most important: the PersistEvent is in the same jar as SessionImpl. I even added the hibernate-core jar explicitly in my pom, but I got the same error. Do you know of other such issues? Maybe I am doing dependency management in the wrong way?
Or maybe this behavior is normal when you don't setup transaction well?
Thanks and regards,
Ivan