-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate in Weblogic not persisting changes
PostPosted: Tue Sep 14, 2004 2:06 pm 
Newbie

Joined: Tue Jun 15, 2004 10:45 am
Posts: 18
Location: Boston, USA
Hi all,

I have been searching the forums for similar issues and found a few that have helped but I am still stuck with the same problem:

I am using hibernate 2.1 within weblogic 8.1.3 and oracle 9.2. I can retrieve successfully from the DB but when I make a change and attempt to persist the changes never appear in the DB. I may have tripped over my own toes by taking bits and pieces from other people posts and responses so I am hoping someone could give a quick look to see if they see anything obvious:

My hibernate.cfg.xml:
Code:
<hibernate-configuration>

   <session-factory name="hibernate.session-factory.Oracle">
       <property name="connection.datasource">myserverDataSource</property>
       <property name="show_sql">true</property>
       <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
       <property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
       <property name="jndi.url">t3://127.0.0.1:7001</property>
       <property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup </property>
       <property name="hibernate.transaction.factory_class">javax/transaction/UserTransaction</property>
       <property name="jta.UserTransaction">net.sf.hibernate.transaction.JTATransactionFactory</property>

     <mapping resource="com/mycompany/model/Student.hbm.xml"/>

  </session-factory>
</hibernate-configuration>



Hibernate mapping file:
Code:
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="edu.mit.ssit.mysample.model.Student"
    table="STUDENT"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="STUDENT"
    </meta>

    <composite-id>
        <meta attribute="class-description" inherit="false">
           @hibernate.id
            generator-class="assigned"
        </meta>
        <key-property
            name="studentId"
            column="STUDENT_ID"
            type="java.math.BigDecimal"
            length="22"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="STUDENT_ID"
            </meta>
        </key-property>
        <key-property
            name="firstName"
            column="FIRST_NAME"
            type="java.lang.String"
            length="30"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="FIRST_NAME"
            </meta>
        </key-property>
        <key-property
            name="lastName"
            column="LAST_NAME"
            type="java.lang.String"
            length="30"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="LAST_NAME"
            </meta>
        </key-property>
        <key-property
            name="gender"
            column="GENDER"
            type="java.lang.String"
            length="1"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="GENDER"
            </meta>
        </key-property>
        <key-property
            name="graduationYear"
            column="GRADUATION_YEAR"
            type="java.lang.Integer"
            length="4"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="GRADUATION_YEAR"
            </meta>
        </key-property>
    </composite-id>   


    <!-- associations -->

</class>
</hibernate-mapping>


My update call (inside a DAO):
Code:
public void updateStudent(Student student) throws HibernateException
   {
       Session hbnsession = null;
      List results = null;
     
      try
      {
         
         hbnsession = HibernateSessionManager.getSession();
         //TODO: add optimistic locking so we get the student, compare the details
         //and if no changes update else return a RecordChangedException
         hbnsession.update(student);
      }
      catch (HibernateException e)
     {
         log.error(e.getMessage());
         //TODO: map this to a generic infrastructure exception
         throw e;
     }
   
   }


finally the session bean method that calls the dao:
Code:
  public void updateStudent(Student criteria)
      throws Exception
  {
      log.info("updating student ID:"+criteria.getStudentId());
      try
      {
          new StudentDAO().updateStudent(criteria);
          //we want our container to handle transactions
          HibernateSessionManager.commitTransaction();
      }
      catch(Exception e)
      {
          throw e; //we logged it already
      }
      finally
      {
          HibernateSessionManager.closeSession();
      }
     
  }


Any advice would really be appreciated.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 2:58 pm 
Newbie

Joined: Tue Jun 15, 2004 10:45 am
Posts: 18
Location: Boston, USA
I think I am getting closer...

looking at the DEBUG level output I get:

Hibernate Exception when attempting to create the session factory:Failed to instantiate TransactionFactory: java.lang.InstantiationException: javax.transaction.UserTransaction

Looking in the weblogic console the UserTransaction object is there. Does hibernate look somewhere different for its classpath?? My app is deployed in an EAR file.

Previously I was not adding the reference to the userTransaction into my hibernate.cfg.xml and I could retrieve data but not see any persisted changes.

I am using a connection pool specified in weblogic with the Oracle thin driver. Do I perhaps need to change drivers to an XA driver?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 4:01 pm 
Newbie

Joined: Tue Jun 15, 2004 10:45 am
Posts: 18
Location: Boston, USA
ok so I have cleaned it up and have the following DEBUG output which should hopefully help:
Code:
Starting new database transaction in this thread.
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (?:?) - Starting new database transaction in this thread.
Opening new Session for this thread.
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (?:?) - Opening new Session for this thread.
JNDI lookup: hibernate.session-factory.Oracle
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionFactoryObjectFactory.java:69) - JNDI lookup: hibernate.session-factory.Oracle
lookup: uid=929282ebfefe824500fefe8248ff0000
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionFactoryObjectFactory.java:145) - lookup: uid=929282ebfefe824500fefe8248ff0000
opened session
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:542) - opened session
Looking for UserTransaction under: javax.transaction.UserTransaction
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (JTATransaction.java:130) - Looking for UserTransaction under: javax.transaction.UserTransaction
Obtained UserTransaction
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (JTATransaction.java:142) - Obtained UserTransaction
updating [edu.mit.ssit.mysample.model.Student#edu.mit.ssit.mysample.model.Student@7cf599[studentId=1002,firstName=Barney,lastName=Rubble,gender=M,graduationYear=3000]]
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:1432) - updating [edu.mit.ssit.mysample.model.Student#edu.mit.ssit.mysample.model.Student@7cf599[studentId=1002,firstName=Barney,lastName=Rubble,gender=M,graduationYear=3000]]
Retrieved out current transaction net.sf.hibernate.transaction.JTATransaction@1e02286
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (?:?) - Retrieved out current transaction net.sf.hibernate.transaction.JTATransaction@1e02286
Has it been committed?: false
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (?:?) - Has it been committed?: false
Was it rolled back?: false
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (?:?) - Was it rolled back?: false
Committing database transaction of this thread.
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (?:?) - Committing database transaction of this thread.
commit
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (JTATransaction.java:50) - commit
flushing session
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2235) - flushing session
Flushing entities and processing referenced collections
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2428) - Flushing entities and processing referenced collections
Updating entity: [edu.mit.ssit.mysample.model.Student#edu.mit.ssit.mysample.model.Student@7cf599[studentId=1002,firstName=Barney,lastName=Rubble,gender=M,graduationYear=3000]]
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2522) - Updating entity: [edu.mit.ssit.mysample.model.Student#edu.mit.ssit.mysample.model.Student@7cf599[studentId=1002,firstName=Barney,lastName=Rubble,gender=M,graduationYear=3000]]
Processing unreferenced collections
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2771) - Processing unreferenced collections
Scheduling collection removes/(re)creates/updates
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2785) - Scheduling collection removes/(re)creates/updates
Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2259) - Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2264) - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
listing entities:
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (Printer.java:75) - listing entities:
edu.mit.ssit.mysample.model.Student{}
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (Printer.java:82) - edu.mit.ssit.mysample.model.Student{}
executing flush
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2348) - executing flush
Updating entity: [edu.mit.ssit.mysample.model.Student#edu.mit.ssit.mysample.model.Student@7cf599[studentId=1002,firstName=Barney,lastName=Rubble,gender=M,graduationYear=3000]]
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (EntityPersister.java:646) - Updating entity: [edu.mit.ssit.mysample.model.Student#edu.mit.ssit.mysample.model.Student@7cf599[studentId=1002,firstName=Barney,lastName=Rubble,gender=M,graduationYear=3000]]
post flush
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:2815) - post flush
Closing Session of this thread.
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (?:?) - Closing Session of this thread.
closing session
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:560) - closing session
transaction before completion callback
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (CacheSynchronization.java:24) - transaction before completion callback
transaction after completion callback, status: 3
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (CacheSynchronization.java:28) - transaction after completion callback, status: 3
transaction completion
DEBUG [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] (SessionImpl.java:572) - transaction completion


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 4:34 pm 
Newbie

Joined: Tue Jun 15, 2004 10:45 am
Posts: 18
Location: Boston, USA
sorry... it was my fault.

Just had to "talk to the bear" and realize I had not finished creating my table properly... but on the positive side still better than EJB!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.