-->
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.  [ 6 posts ] 
Author Message
 Post subject: commit in a CMT session bean context not commiting to the DB
PostPosted: Mon May 14, 2007 12:31 pm 
Newbie

Joined: Mon May 14, 2007 12:13 pm
Posts: 8
Hibernate version: 3.2.3

session factory configuration:

<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432Repository1</property>
<property name="hibernate.connection.isolation">4</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="hibernate.order_updates">false</property>

<property name="hibernate.transaction.auto_close_session">true</property>
<property name="transaction.flush_before_completion">true</property>
<property name="hibernate.jdbc.batch_size">0</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.pool_size">5</property>
<property name="idle-timeout-minutes">3</property>

</session-factory>


Mapping documents:


<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="TriggerWrapper">
<id name="id" column="primaryKey"/>
<property name="triggerName"/>
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
/*
Start of relevant code.
This code executes in the context of a CMT Session bean
*/

Session hibSess = anHIBSessionFactory.getCurrentSession();

Transaction tx = hibSess.getTransaction();


tx.begin();

TriggerWrapper myObj = new TriggerWrapper("aTest");

hibSess.save(myObj);

tx.commit();

/*
End of relevent code
*/





Database name and version: PostgreSQL 8.2.4


When the above Java code is executed, there isn't a new TriggerWrapper
instance saved to the DB.

What am I doing wrong here.

Thanks in advance.


Top
 Profile  
 
 Post subject: More info on this anomaly
PostPosted: Tue May 15, 2007 12:40 pm 
Newbie

Joined: Mon May 14, 2007 12:13 pm
Posts: 8
What is really odd about this is.
When setting the show-sql to true.

I can see the generated insert statements.
However, these statements never make it to the DB.
Because, again, there aren't any new rows that have been inserted.


Another thing to note.
If I run my junit tests more than once without restarting the app-server.
I get a duplicate key exception on the instance I attempt to save.

When I restart the app-server. I can then save the newly created trigger
wrapper instance.

This says to me that there is a problem with the hibernate session instance
not flushing it's contents to the DB.


Anyone care to comment.


Top
 Profile  
 
 Post subject: Can only save with autoCommit true
PostPosted: Tue May 15, 2007 4:40 pm 
Newbie

Joined: Mon May 14, 2007 12:13 pm
Posts: 8
The only way I found to persist a an object with 3.2.3ga in a Transaction context
is by setting the "hibernate.connection.autocommit" property to true.


What is up ??


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 8:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
CMT = Container managed Transactions - The container provides the transaction operations on the boundaries (usually a method call). Your code does not appear to compatible with CMT. I would think you need to review what you have done as basically you are not using CMT.

I suggest you read Christians book and the samples from the book for proper transaction management and how to set it up correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 2:59 pm 
Newbie

Joined: Mon May 14, 2007 12:13 pm
Posts: 8
Even when I reduced the code to
Code:
/*
Start of relevant code.
This code executes in the context of a CMT Session bean
*/

Session hibSess = anHIBSessionFactory.getCurrentSession();

TriggerWrapper myObj = new TriggerWrapper("aTest");

hibSess.save(myObj);



Which, from what I understand, should have saved and committed instance
myObj to the DB since it executes in the context of a CMT.

But, myObj instance is never saved.

I have seen other posting here in this forum regarding the same problem of Objects NOT being saved, both in the context of using the JTA api and also in the context of CMT,
with no clear cut answer.

This must be a configuration issue, but, where can I find the correct configuration
for session factory in order to use CMT.


Thanks in advance.

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 8:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
For my current project (and most previous projects), I am using CMT extensively. The tx boundaries are set via SLSB method signature that a transaction should be started. In the case of JBoss I have used the MBean method (SAR/HAR) for session factory setup. The SLSB setup the the transaction (since its required) a JNDI lookup gets the Session factory thus acces to the session and away we go. All works well. Other than how you getting the Session factory session (and then maybe not depending on what behind that method) the only reason your having any issues is the initial setup/configuration. I suggest you look at some sample code and try again. Alternatively, try non CMT transaction just to make sure you going in the right direction.


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