-->
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.  [ 2 posts ] 
Author Message
 Post subject: Container Managed Transaction integration problem (oc4j)
PostPosted: Wed Sep 15, 2004 2:21 pm 
Newbie

Joined: Wed Sep 15, 2004 11:29 am
Posts: 4
Hi all! I'm having trouble to integrate Hibernate with Oracle Application Server, Oc4j. I'm using Container-Managed transactions (attribute Required) and accesing Hibernate layer from EJBs.

The problem is the following: I configured hibernate to work with container transactions (JTATransactionFactory) but Hibernate seems not to be using the container opened transaction. After doing a session.save() the EJB does a context.setRollbackOnly() but the changes persist in the database anyway.

My configuration is:
Hibernate version: 2.1.4

hibernate.cfg
:
<hibernate-configuration>
<session-factory name="java:comp/env/hibernate/SessionFactory">
<property name="connection.datasource">jdbc/i9julioDS</property>
<property name="show_sql">true</property>
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.query.substitutions">1</property>
<property name="hibernate.max_fetch_depth">1</property>
<property name="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory</property>
property name="hibernate.transaction.manager_lookup_class"> net.sf.hibernate.transaction.OrionTransactionManagerLookup</property>
<property name="jta.UserTransaction">
java:comp/UserTransaction</property>


Code between sessionFactory.openSession() and session.close():

public void persist(Object entity){
SessionFactory sessionFactory=new Configuration().
configure().buildSessionFactory();

Session session = sessionFactory.openSession();
Long storedId = (Long)session.save(entity);

session.flush();
session.close();
}

Name and version of the database you are using: Mysql 4.1.1a-alpha-nt

The generated SQL (show_sql=true):

This is the generated sql when I save an entity and after the control returns to the EJB the method context.setRollbackOnly() is called:

HttpRequestHandler-107 net.sf.hibernate.id.IncrementGenerator - fetching initial value: select max(id) from seguridad_perfil

HttpRequestHandler-107 net.sf.hibernate.id.IncrementGenerator - first free id: 11

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - generated identifier: 11

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - saving [com.i9dejulio.seguridad.entities.Perfil#11]

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - flushing session

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections

HttpRequestHandler-107 net.sf.hibernate.impl.Printer - listing entities:

HttpRequestHandler-107 net.sf.hibernate.impl.Printer - com.i9dejulio.seguridad.entities.Perfil{nombre=testPerfil, menues=null, id=11}

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - executing flush

HttpRequestHandler-107 net.sf.hibernate.persister.EntityPersister - Inserting entity: [com.i9dejulio.seguridad.entities.Perfil#11]

HttpRequestHandler-107 net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets

HttpRequestHandler-107 net.sf.hibernate.SQL - insert into seguridad_perfil (nombre, id) values (?, ?)

04/09/15 15:16:17 Hibernate: insert into seguridad_perfil (nombre, id) values (?, ?)

HttpRequestHandler-107 net.sf.hibernate.impl.BatcherImpl - preparing statement

HttpRequestHandler-107 net.sf.hibernate.persister.EntityPersister - Dehydrating entity: [com.i9dejulio.seguridad.entities.Perfil#11]

HttpRequestHandler-107 net.sf.hibernate.type.StringType - binding 'testPerfil' to parameter: 1

HttpRequestHandler-107 net.sf.hibernate.type.LongType - binding '11' to parameter: 2

HttpRequestHandler-107 net.sf.hibernate.impl.BatcherImpl - Adding to batch

HttpRequestHandler-107 net.sf.hibernate.impl.BatcherImpl - Executing batch size: 1

HttpRequestHandler-107 net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets

HttpRequestHandler-107 net.sf.hibernate.impl.BatcherImpl - closing statement

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - post flush

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - closing session

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - disconnecting session

HttpRequestHandler-107 net.sf.hibernate.impl.SessionImpl - transaction completion



I'm not sure if my configuration is not correct, if this might be a bug or if hibernate has problems integrating with Oc4j.

I would appreciate any help given!

Best regards,
Franco


Top
 Profile  
 
 Post subject: Allready figured it out!!!
PostPosted: Fri Sep 17, 2004 10:09 am 
Newbie

Joined: Wed Sep 15, 2004 11:29 am
Posts: 4
I found the solution, mysql tables must be of type=InnoDb in order to get transactions... my hibernate configuration was ok, I changed that and got transactions.


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