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

Thread: Auto Flush not working for Spring 3.1 LocalEntityManagerFactoryBean+Hibernate 4+JTA

  1. #11
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Hello adrianshum

    1) Check the API for org.springframework.transaction.jta.WebSphereUowTr ansactionManager

    Perhaps it require some special property to be used, since the error message is related with no transaction is in progress

    2) Where you are making the relation between the Transaction and JPA?
    They are declared but seems isolated between them.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #12

    Default

    @Marten: May I know if you are declaring all your mapped class in persistence.xml explicitly? One of the reason for me not to use persistence.xml is the newly added packageToScan feature in LocalContainerEntityManager which save me trouble in the maintenance of persistence.xml (I used to write a maven plugin for that)

    And, in your deployment, do you simply package all those hibernate dependencies with the WAR? Or do you need to setup Websphere by putting some JARs Websphere? Are you using the default parent-first classloading strategy? (In my old day using older version of Weblogic, I need to do some pre-setup by putting hibernate related JARs under Weblogics, though I don't think it is necessary as things mostly works this time)

    @dr_pompeii:
    1) Have had a brief look on it, seems there is nothing special that I can set. Just to clarify, transaction is working if I am using CMTTransactionFactory (only auto-flushing is not working)

    2) Well, I mostly follow this setting by following misc reference on the web. Though I am not really sure, but I believe it is how it work:

    - Transaction Manager is in fact managed by container
    - those <tx:jta-transaction-manager /> or WebSphereUowTransactionManager is in fact looking up it from container
    - Hibernate is looking up the transaction manager from container by providing hibernate.transaction.manager_lookup_class (org.hibernate.transaction.WebSphereExtendedJTATra nsactionLookup) and hibernate.transaction.factory_class (org.hibernate.engine.transaction.internal.jta.CMT TransactionFactory) (and probably jta.platform too). All these make Hibernate lookup the same transaction manager (and hence, create its corresponding Session) as which Spring is using for transaction management.
    Last edited by adrianshum; Oct 16th, 2012 at 08:53 PM.

  3. #13

    Default

    A "Good" news: Using persistence.xml, as what @Marten suggested, is working.

    It seems that even I am having almost identical properties set directly on LocalContainerEntityManager vs in persistence.xml, it works fine only in persistence.xml

    It seems obvious to me that is a bug of Spring 3.1. I am going to raise a bug to Spring for that after I done some more cleanup and testing on that.

    Will adopt the persistence.xml way for the time being as workaround

  4. #14
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    First off all glad it worked . To anser your questions.

    Quote Originally Posted by adrianshum
    May I know if you are declaring all your mapped class in persistence.xml explicitly? One of the reason for me not to use persistence.xml is the newly added packageToScan feature in LocalContainerEntityManager which save me trouble in the maintenance of persistence.xml (I used to write a maven plugin for that)
    What I posted is all we have and use so no explicit classes in persistence.xml nor packagesToScan. JPA is perfectly capably of detecting @Entity classes in the same archive as where the persistence.xml is declared.

    Quote Originally Posted by adrianshum
    And, in your deployment, do you simply package all those hibernate dependencies with the WAR? Or do you need to setup Websphere by putting some JARs Websphere? Are you using the default parent-first classloading strategy? (In my old day using older version of Weblogic, I need to do some pre-setup by putting hibernate related JARs under Weblogics, though I don't think it is necessary as things mostly works this time)
    We use parent-last/application-first (IBM changes the names frequently ) classloading and everything is packed inside the war. Mainly because we want to use hibernate and we package our own JSF implementation. This requires some classloading trickery.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #15

    Default

    After some further trial-and-error, here is the actual problem:

    1) I can move almost all settings from persistence.xml to Spring's config, leaving only the <persistence-unit name="foo" transaction-type"="JTA"> line in persistence.xml. It works fine.
    2) I need to have transaction-type = "JTA" in persistence.xml. Having "RESOURCE_LOCAL" is giving the same error of "no transaction in progress". (Though it works in my previous projects with Spring 2.5 + Hibernate 3 + WebLogic)


    (A wild guess) It seems to be that for the xml-less LocalContainerEntityManagerFactoryBean bootstrapping method, it is making the native entity manager intialized as it is having a persistence.xml with transaction-type as "LOCAL_RESOURCES" (though we haven't declare it anywhere), which caused the problem (at least for the combination of framework/system I am using this time).

    As a workaround, I have to leave persistence.xml in my JAR. However, by doing that it left packagesToScan useless (I believe it cannot co-exists with persistence.xml). It will still be fine for me in this moment (but I will need to find some way later to make multiple JARs-with-entities possible)
    Last edited by adrianshum; Oct 17th, 2012 at 05:15 AM.

  6. #16
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I assumed you had the correct transaction_type.

    You could try and configure an additional PersistenceUnitPostProcessor implementation which sets the transaction type to JTA.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #17

    Default

    I didn't expect the transaction type can be the cause of problem, as Spring 3.1 provide the xml-less JPA bootstrapping, and, in my past project, I used to use LOCAL_RESOURCES transaction type in persistence.xml and it works fine (Spring 2.5 + Hibernate 3 + WebLogic).

    Good suggestion on the PU Post Processor, lemme have a try on that

  8. #18
    Join Date
    Nov 2007
    Posts
    16

    Default

    Hi Adrian,

    I'm also stuck in similar problem with tech stack Spring data JPA, Hibernate, WebSphere 6.1.0.39. Wondering if you managed to raise a bug as you mentioned in the post. Currently I'm not in favour of using the persistence.xml but will use if its the only option.

    Thanks & Regards,
    Irfan

  9. #19

    Default

    Marten/adrianshum

    Thanks for the posts, this one had me confused for a few minutes. I just wanted to add if you are using the classpath scanning on the LocalContainerEntityManagerFactoryBean that is fine just make sure you set the JtaDatasource, not the DataSource

    Code:
            @Bean
            public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean()
            {
                LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
                lef.setJtaDataSource(datasource());
                lef.setPackagesToScan("com.xxx.yyy.model.entity");
                lef.setJpaProperties(jpaProperties());
                lef.setJpaVendorAdapter(jpaVendorAdapter());
                return lef;
            }

Tags for this Thread

Posting Permissions

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