Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: HibernateTransactionManager doesn't work

  1. #11
    Join Date
    Mar 2007
    Posts
    515

    Default

    I suspect you have passed a child entity or collection, which is initialized in other session, to Shares entity and, when saving, Hibernate tries to save the child entity or collection and thus resulting in lazy-init exception.

  2. #12
    Join Date
    Jun 2007
    Posts
    25

    Default

    Yes, exactly. Andrei Stefan thanks a lot for your tips. It was one of the childes collection that was initialized in earlier session.

    But now I have another problem, because my transaction doesn't rollback when there is an exception.

  3. #13
    Join Date
    Mar 2007
    Posts
    515

  4. #14
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by Andrei Stefan View Post
    If it's a runtime exception, the rollback will be done automatically. If it's another exception, you have to specify this in your transaction interceptor attributes
    Indeed, the root exception is effectively thrown away and wrapped.
    Code:
    throw new Exception(e.toString());
    Last edited by karldmoore; Aug 29th, 2007 at 11:14 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  5. #15
    Join Date
    Jun 2007
    Posts
    25

    Default

    Ok, I don't have code for tests, but to check my transactions I throw exception in my code. Lets say after first loop's run and then hibernateexception is thrown. Unfortunatelly, there is no rollback

    I added to configuration file some changes:

    Code:
           <bean id="userTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    		<property name="transactionManager">
    			<ref local="hibernateTransactionManager"/>
    		</property>
    		<property name="transactionAttributeSource">
    			<value>
    				org.bivela.business.facade.UserFacadeInterface.updateShareholders=PROPAGATION_REQUIRED,+HibernateException
    			</value>
    		</property>
    	</bean>
    and my debug file looks like:

    Code:
    2007-07-02 08:44:36,020 DEBUG [org.hibernate.engine.StatefulPersistenceContext] initializing non-lazy collections
    2007-07-02 08:44:36,021 DEBUG [org.springframework.orm.hibernate3.HibernateTemplate] Not closing pre-bound Hibernate Session after HibernateTemplate
    2007-07-02 08:44:36,021 DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] Completing transaction for [org.bivela.business.facade.UserFacadeInterface.updateShareholders] after exception: java.lang.Exception: org.hibernate.HibernateException: Blad wymuszony
    2007-07-02 08:44:36,021 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] Applying rules to determine whether transaction should rollback on java.lang.Exception: org.hibernate.HibernateException: Blad wymuszony
    2007-07-02 08:44:36,021 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] Winning rollback rule is: null
    2007-07-02 08:44:36,021 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] No relevant rollback rule found: applying superclass default
    2007-07-02 08:44:36,022 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] Triggering beforeCommit synchronization
    2007-07-02 08:44:36,035 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] Triggering beforeCompletion synchronization
    2007-07-02 08:44:36,036 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] Initiating transaction commit
    2007-07-02 08:44:36,036 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@869e8f]
    2007-07-02 08:44:36,036 DEBUG [org.hibernate.transaction.JDBCTransaction] commit
    2007-07-02 08:44:36,036 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] processing flush-time cascades
    2007-07-02 08:44:36,036 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] dirty checking collections
    2007-07-02 08:44:36,037 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 insertions, 0 updates, 0 deletions to 6 objects
    2007-07-02 08:44:36,038 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    2007-07-02 08:44:36,038 DEBUG [org.hibernate.pretty.Printer] listing entities:
    2007-07-02 08:44:36,038 DEBUG [org.hibernate.pretty.Printer] org.bivela.dto.bivela.Companies{purpose=money, employeesNumber=123, country=org.bivela.dto.bivela.Countries#1, zipCode=12345, companyStatus=SA, address=Doki 2, state=pomorskie, capital=123423, fiscalPeriod=01-01, name=Sunreef Yachts, city=gdansk, id=1}
    2007-07-02 08:44:36,038 DEBUG [org.hibernate.pretty.Printer] org.bivela.dto.bivela.Companies{purpose=money, employeesNumber=123, country=org.bivela.dto.bivela.Countries#1, zipCode=12345, companyStatus=SARL, address=Doki 2, state=pomorskie, capital=123, fiscalPeriod=01-01, name=htep, city=Gdansk, id=2}
    2007-07-02 08:44:36,038 DEBUG [org.hibernate.pretty.Printer] org.bivela.dto.bivela.Companies{purpose=fdksf, employeesNumber=123, country=org.bivela.dto.bivela.Countries#1, zipCode=12345, companyStatus=SARL, address=Doki 2, state=pomorskie, capital=123, fiscalPeriod=01-01, name=htep2, city=gdansk, id=3}
    2007-07-02 08:44:36,047 DEBUG [org.hibernate.pretty.Printer] org.bivela.dto.bivela.Shares{shareholder=org.bivela.dto.bivela.Shareholders#1, changeDate=2007-07-02 08:44:35, quantity=60.00, id=8, company=org.bivela.dto.bivela.Companies#1}
    2007-07-02 08:44:36,048 DEBUG [org.hibernate.pretty.Printer] org.bivela.dto.bivela.Shareholders{contact=null, type=artificial person, id=1, company=org.bivela.dto.bivela.Companies#2}
    2007-07-02 08:44:36,048 DEBUG [org.hibernate.pretty.Printer] org.bivela.dto.bivela.Shareholders{contact=null, type=artificial person, id=3, company=org.bivela.dto.bivela.Companies#3}
    2007-07-02 08:44:36,420 DEBUG [org.hibernate.transaction.JDBCTransaction] re-enabling autocommit
    2007-07-02 08:44:36,420 DEBUG [org.hibernate.transaction.JDBCTransaction] committed JDBC Connection
    2007-07-02 08:44:36,421 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
    2007-07-02 08:44:36,421 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    2007-07-02 08:44:36,421 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] Triggering afterCommit synchronization
    2007-07-02 08:44:36,421 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] Triggering afterCompletion synchronization
    2007-07-02 08:44:36,421 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Clearing transaction synchronization
    2007-07-02 08:44:36,422 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Removed value [org.springframework.orm.hibernate3.SessionHolder@142022d] for key [org.hibernate.impl.SessionFactoryImpl@1c1c9dc] from thread [http-0.0.0.0-8443-2]
    2007-07-02 08:44:36,422 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1233bdc] for key [org.apache.commons.dbcp.BasicDataSource@5c2445] from thread [http-0.0.0.0-8443-2]
    2007-07-02 08:44:36,422 DEBUG [org.springframework.orm.hibernate3.HibernateTransactionManager] Closing Hibernate Session [org.hibernate.impl.SessionImpl@869e8f] after transaction
    2007-07-02 08:44:36,422 DEBUG [org.springframework.orm.hibernate3.SessionFactoryUtils] Closing Hibernate Session
    2007-07-02 08:44:36,422 DEBUG [org.springframework.web.servlet.DispatcherServlet] Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@15d63da
    2007-07-02 08:44:36,423 DEBUG [org.springframework.web.servlet.DispatcherServlet] Could not complete request
    java.lang.Exception: org.hibernate.HibernateException: Blad wymuszony
    	at org.bivela.business.facade.UserFacade.updateShareholders(UserFacade.java:1393)
    What am I doing wrong?

  6. #16
    Join Date
    Mar 2007
    Posts
    515

    Default

    First of all, I don't think you should have added +HibernateException to your properties - this exception is a RuntimeException and the transaction roll-backs by default in case this one is thrown.
    Second,
    A "+" before an exception name substring indicates that transactions should commit even if this exception is thrown; a "-" that they should roll back.
    from http://www.springframework.org/docs/...uteEditor.html
    so, it should have been with a "-".

    Try removing the +HibernateException from your attributes and test again.

  7. #17
    Join Date
    Jun 2007
    Posts
    25

    Default

    First I've change HibernateException with '-' and then I've deleted this exception from configuration file and still it doesn't work correctly.

    I'm wondering why in debug file I have:
    Code:
    Winning rollback rule is: null
    and then transaction is commited.

    Maybe there is a problem.

  8. #18
    Join Date
    Jun 2007
    Posts
    25

    Default

    OK, everything works fine with hibernate transaction manager.

    Now I have another problem, because I need to change Hibernate Transaction Manager to JTA Transaction Manager.

    Can somebody tell me what I have to change in my configuration?

  9. #19
    Join Date
    Mar 2007
    Posts
    515

    Default

    What was the problem with Hibernate transaction manager roll-back ?

  10. #20
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by martique View Post
    OK, everything works fine with hibernate transaction manager.
    I'm not quite sure I understand this, weren't you original using the HibernateTransactionManager?
    Last edited by karldmoore; Aug 29th, 2007 at 11:14 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

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