Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: How to integrate Spring and Hibernate Entitymanager?

  1. #11
    Join Date
    Dec 2005
    Posts
    2

    Default

    Guys,

    What versions of Hibernate, Hibernate Entity Manager and Spring are you using?

    I've grabbed the sample code from Thomas' presentation, but can't seem to get it to do what I want. Keeping the code as it is, I get:

    Code:
    java.lang.NullPointerException
    	at com.springdeveloper.service.BeerDistributorServiceJpa.getCustomerList(BeerDistributorServiceJpa.java:27)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
            ...
    getEntityManager() is null. I can force creation of it by EntityManagerFactory.createEntityManager(), but them I'm faced with

    Code:
    javax.persistence.TransactionRequiredException: no transaction is in progress
    	at org.hibernate.ejb.AbstractEntityManagerImpl.checkTransactionActive(AbstractEntityManagerImpl.java:130)
    	at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:145)
    	at com.springdeveloper.service.BeerDistributorServiceJpa.saveCustomer(BeerDistributorServiceJpa.java:48)
    I'm using the JpaTransactionManager as supplied in the sample code, but it doesn't seem to create a new tx when required.

    FYI, Hibernate 3.1rc1, Hibernate EM 3.1beta4, Spring 1.3RC1

    Can anyone shed some light on this?

    thanks!

  2. #12
    Join Date
    Jul 2005
    Location
    Rüdesheim, Germany
    Posts
    29

    Default

    I've put together a small tutorial describing all this stuff:

    http://jroller.com/page/sbeigel?entr...va_persistence

    Sebastian

  3. #13
    Join Date
    Dec 2005
    Posts
    2

    Default

    Top work!

    I was extending JpaSupport (not JpaDaoSupport) and using getEntityManager() rather than using the JpaTemplate.

    All works now.. thanks for your help

  4. #14
    Join Date
    Dec 2005
    Posts
    1

    Default

    Is the JPA preview code still available? I noticed that it was removed from CVS by robharrop on 12/7/05 with the comment "Removed old JPA code". Has this code simply been moved elsewhere and if so where?

  5. #15
    Join Date
    Jul 2005
    Location
    Rüdesheim, Germany
    Posts
    29

    Default

    It's moved to the sandbox -- and currently not included in the 2.0 milestone builds. Don't know why actually...

    Sebastian

  6. #16
    Join Date
    Aug 2004
    Posts
    1,107

    Default

    That's because the spec is not final yet and the api is still undergoing changes. So for now we have to use it out of the sandbox.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  7. #17
    Join Date
    Aug 2004
    Location
    Columbus, OH
    Posts
    65

    Default

    Is the code in the sandbox currently compatible with the Spring 2.0M2 builds?

    I take it the code in the sandbox is not included in the nightly snapshots?

  8. #18
    Join Date
    Jul 2007
    Posts
    5

    Default

    Quote Originally Posted by dth View Post
    Top work!

    I was extending JpaSupport (not JpaDaoSupport) and using getEntityManager() rather than using the JpaTemplate.

    All works now.. thanks for your help
    My DAO extend JpaDaoSupport and yet I get null when call getEntityManager().
    Do you mean I should use those "find" methods of JpaTemplate object, instead of using EntityManager? I thought that since we use JPA here anyway, than JpaTemplate uses EntityManager underneath, so why can't I get a reference to it?

    Is it because of different exception model? Using EntityManager directly implies dealing with checked exceptions as opposed to wraped exceptions, am I right?

    Thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •