-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Entity Manager does not do insert upon persist
PostPosted: Tue Jun 21, 2011 4:55 am 
Newbie

Joined: Tue Oct 20, 2009 4:53 pm
Posts: 4
Location: Sofia, Bulgaria
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.