-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with transactions..
PostPosted: Mon Nov 08, 2004 2:36 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:49 pm
Posts: 33
Location: Bogota, Colombia
Hi, my problem is simple to explain: when I want to create/update/delete an item from any class it works when I do not use hibernate transactions! In addition, when I use transactions, no exception is thrown. Why could this be happening?

This code works:
Code:
try
{
  Session sess = HibernateUtil.getSession();

  Constant con = new con(name, code, ParentId);
  sess.save(con);
  HibernateUtil.flushSession();
}
catch(HibernateException e)
{
  e.printStackTrace();
  throw new BusinessException(ErrorMessage.INSERT_FAILURE);
}
finally
{
  HibernateUtil.closeSession();
}


This one doesnt:
Code:
try
{
  Session sess = HibernateUtil.getSession();
  HibernateUtil.beginTransaction();

  Constant con = new con(name, code, ParentId);
  sess.save(con);
  HibernateUtil.commitTransaction();
}
catch(HibernateException e)
{
  HibernateUtil.rollbackTransaction();
  throw new BusinessException(ErrorMessage.INSERT_FAILURE);
}
finally
{
  HibernateUtil.closeSession();
}


The big difference between both codes (besides the direct use of a transaction) is the flush after the object has been persisted. Isnt commit() supposed to do the flushing? (as it is illustred in the log excerpt below) or do I need to do it explicitly?

I'm using Jboss 3.0.6's JTA for transactions. Thanks for your help!


Hibernate version:2.1.6

Hibernate Service XML:
Code:
<server>
   <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=app.Hibernate">
       <depends>jboss.jca:service=RARDeployer</depends><depends>jboss.jca:service=LocalTxCM,name=matriculasDS</depends>
       <attribute name="MapResources">Constant.hbm.xml</attribute>
       <attribute name="JndiName">java:/app.HibernateFactory</attribute>
       <attribute name="Datasource">java:/appDS</attribute>
       <attribute name="Dialect">net.sf.hibernate.dialect.Oracle9Dialect</attribute>
       <attribute name="UseOuterJoin">false</attribute>
       <attribute name="ShowSql">true</attribute>
       <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
       <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
       <attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>
       <attribute name="UseQueryCache">true</attribute>
       <attribute name="QuerySubstitutions">true 'Y', false 'N', yes 'Y', no 'N'</attribute>
   </mbean>
</server>


Mapping documents:
Code:
    <class
        name="Constant"
        table="CONSTANTS"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
    >

        <jcs-cache usage="read-write" />

        <id
            name="id"
            column="ID"
            type="java.lang.Long"
        >
            <generator class="increment">
            </generator>
        </id>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="NAME"
            length="100"
        />

        <property
            name="code"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="CODE"
            length="10"
        />

        <many-to-one
            name="parent"
            class="Constant"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="CONS_ID"
        />

        <set
            name="children"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan"
            sort="unsorted"
        >
            <cache
                usage="read-write"
             />

              <key
                  column="ID"
              >
              </key>

              <one-to-many
                  class="Constant"
              />

        </set>

    </class>


The generated SQL (show_sql=true):
NONE! Hibernate just fetches "select max(ID) from CONSTANTS", for the increment id generator!

Debug level Hibernate log excerpt:
Code:
2004-11-08 13:09:08,709 DEBUG [com.edesa.matri.common.HibernateUtil] Opening new Session for this thread.
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: matriculas.HibernateFactory
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=4028803200195cd50100195cdee10000
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionImpl] opened session
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionImpl] loading [com.edesa.matri.persistence.Constant#1046]
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionImpl] attempting to resolve [com.edesa.matri.persistence.Constant#1046]
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.cache.ReadWriteCache] Cache lookup: 1046
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.cache.ReadWriteCache] Cache hit: 1046
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionImpl] resolved object in second-level cache [com.edesa.matri.persistence.Constant#1046]
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionImpl] creating collection wrapper:[com.edesa.matri.persistence.Constant.children#1046]
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionImpl] Cached Version: null
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.impl.SessionImpl] initializing non-lazy collections
2004-11-08 13:09:08,709 DEBUG [net.sf.hibernate.id.IncrementGenerator] fetching initial value: select max(ID) from CTE
2004-11-08 13:09:08,725 DEBUG [net.sf.hibernate.id.IncrementGenerator] first free id: 1048
2004-11-08 13:09:08,725 DEBUG [net.sf.hibernate.impl.SessionImpl] generated identifier: 1048
2004-11-08 13:09:08,725 DEBUG [net.sf.hibernate.impl.SessionImpl] saving [com.edesa.matri.persistence.Constant#1048]
2004-11-08 13:09:08,725 DEBUG [net.sf.hibernate.engine.Cascades] processing cascades for: com.edesa.matri.persistence.Constant
2004-11-08 13:09:08,725 DEBUG [net.sf.hibernate.engine.Cascades] done processing cascades for: com.edesa.matri.persistence.Constant
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.engine.Cascades] processing cascades for: com.edesa.matri.persistence.Constant
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.engine.Cascades] cascading to collection: com.edesa.matri.persistence.Constant.children
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.engine.Cascades] done processing cascades for: com.edesa.matri.persistence.Constant
2004-11-08 13:09:08,741 DEBUG [com.edesa.matri.common.HibernateUtil] Committing database transaction of this thread.
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.transaction.JTATransaction] commit
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] flushing session
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] Scheduling collection removes/(re)creates/updates
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] executing flush
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] post flush
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.engine.CacheSynchronization] transaction before completion callback
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.engine.CacheSynchronization] transaction before completion callback
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.engine.CacheSynchronization] transaction after completion callback, status: 3
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] transaction completion
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.engine.CacheSynchronization] transaction after completion callback, status: 3
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] transaction completion
2004-11-08 13:09:08,741 DEBUG [net.sf.hibernate.impl.SessionImpl] transaction completion
2004-11-08 13:09:08,756 DEBUG [com.edesa.matri.common.HibernateUtil] Closing Session of this thread.
2004-11-08 13:09:08,756 DEBUG [net.sf.hibernate.impl.SessionImpl] closing session
2004-11-08 13:09:08,756 DEBUG [net.sf.hibernate.impl.SessionImpl] disconnecting session
2004-11-08 13:09:08,756 DEBUG [net.sf.hibernate.impl.SessionImpl] transaction completion
2004-11-08 13:09:08,756 DEBUG [com.edesa.matri.common.HibernateUtil] Session closed.
2004-11-08 13:09:08,944 DEBUG [net.sf.hibernate.impl.SessionImpl] running Session.finalize()
[/code]


Top
 Profile  
 
 Post subject: Still nothing..
PostPosted: Fri Nov 12, 2004 11:21 am 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:49 pm
Posts: 33
Location: Bogota, Colombia
I've had a lot of problems using hibernate's transactions in jboss.. I have read the documentation on the matter and numerous posts about "transactions in jboss", but still havent figured the way to implement them.. Has anyone made it on jboss? if so, what version do I need? can anyone give me a pointer on this, maybe some working transaction code? everytime a transaction goes wrong it says the transaction is "Already marked for rollback" and I have to restart jboss..

Thanks for any help.. I've been posting asking about transactions since about a month ago and still there's no answer.. is this a black box?


Top
 Profile  
 
 Post subject: Just in case..
PostPosted: Tue Nov 23, 2004 11:28 am 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:49 pm
Posts: 33
Location: Bogota, Colombia
I updated to jBoss 3.2.6 and now it works. In other posts in the forum I found there was some bug in jBoss' JTA implementation. Just in case.


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

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.