-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: bullshit JBoss JTA transactions with Hibernate persistance
PostPosted: Thu Jul 06, 2006 2:26 pm 
Beginner
Beginner

Joined: Thu Jun 15, 2006 5:31 am
Posts: 21
I think I am fairly smart guy, but the transaction management in Hibernate with JBoss is ****** obscure.

On a side note I am sick, sick, sick to death of smart ass authors and online article gurus writing a few paragraphs on how to do xyz with 'snippets'. Read my lips:

POST A WORKING EXAMPLE (or get out of my google search results)

I have spent the entire day reading 'Hibernate in action' (or not in my case), online documentation, blogs, blurbs, forums and far fetched figures on how to configure transaction management with JBoss.

Yes I had a single 'insert' working, calling it multiple times with many readonly reads before and after.

No, I have never had the plain jane scenario work of:

a) start a session /transaction/ transaction on a session/ using JTA or not or JNDI or not

b) save (insert) a model

c) generate a failure

d) watch it all rollback

No, one transaction - not a problem. Multiple either my transaction has not successfully started, my session closed itself, the transaction was nested, some hidden AOP flip flop intercepted and crapped over my code,

I could post code, but its pointless - I could never do justice on all the combinations I have tried...

I feel JDBC generated code coming back into my vogue...

...unless someone can save me.


Top
 Profile  
 
 Post subject: works for me
PostPosted: Thu Jul 06, 2006 11:32 pm 
Beginner
Beginner

Joined: Thu Jul 06, 2006 11:09 pm
Posts: 25
Basically, I used the following:

JBoss: 4.0.2 (stable release)
Hiberante 3.1.2 (stable release)
Java SE 1.50 SDK update 6

Please post your current configuration here so I can help you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 12:35 am 
Newbie

Joined: Wed Jul 05, 2006 10:37 pm
Posts: 6
Preach it brother :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 3:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://www.hibernate.org/42.html

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Nested is not supported
PostPosted: Fri Jul 07, 2006 8:38 am 
Newbie

Joined: Tue Jul 04, 2006 9:58 am
Posts: 15
Dude i think you are asking to much from Hibernate. Standard JTA implementation in JBoss 4.0.3SP1 doesn't support PROPAGATION_NESTED.
Take a look into http://jira.jboss.com/jira/browse/JBAS-3364 and http://jira.jboss.com/jira/browse/HIBERNATE-41

I'm currently trying to find a way of how to avoid HIBERNATE-41 in our code. I downloaded and installed latest JBossTS which declares support nested transactions JTA/JTS from http://labs.jboss.com/portal/jbosstm/downloads.

But in fact this Arjuna sh..t doesn't really nest them. The provided semantic has nothing to do with PROPAGATION_NESTED it rather looks like you call a non-transactional method within a transactional method.
Here is what i mean:

Unfortunatelly the latest implementation of JBossTS from http://labs.jboss.com/portal/jbosstm/downloads doesn't implement PROPAGATION_NESTED transaction semantic. Tested versions: JBoss 4.0.3SP1, jbossts-jta-4.2.1Beta1.zip, Hibernate 3.2CR2, TreeCache 1.3.0SP2, JDBC3.0 compliant driver and PostgreSQL 8.0.2

Here is a sample illustrating my point:
(1) I start global tx1 from Spring method call f1() with PROPAGATION_REQUIRED. It registered in gtx table with number 1
(2) tx1 got associated with an opened Hibernate session
(3) invokes Hibernate DAOs to load some domain objects
(4) tx1 calls f2() with PROPAGATION_NESTED
(4.2) No new transaction created in gtx
(5) f2 invokes Hibernate DAO to load 1 domain O1 object and resave it with 1 field updated.
(6) After f2 exit and execution point is back in f1() no commit done for O1 and no record data flushed to DB.

Expected behavior is that after step 5 the nested transaction will be commited and hibernate session object O1 (modified within f2) call will be flushed and DB record updated.
[ Show » ] Yegor Yenikyeyev [07/Jul/06 05:14 AM] Unfortunatelly the latest implementation of JBossTS from http://labs.jboss.com/portal/jbosstm/downloads doesn't implement PROPAGATION_NESTED transaction semantic. Tested versions: JBoss 4.0.3SP1, jbossts-jta-4.2.1Beta1.zip, Hibernate 3.2CR2, TreeCache 1.3.0SP2, JDBC3.0 compliant driver and PostgreSQL 8.0.2 Here is a sample illustrating my point: (1) I start global tx1 from Spring method call f1() with PROPAGATION_REQUIRED. It registered in gtx table with number 1 (2) tx1 got associated with an opened Hibernate session (3) invokes Hibernate DAOs to load some domain objects (4) tx1 calls f2() with PROPAGATION_NESTED (4.2) No new transaction created in gtx (5) f2 invokes Hibernate DAO to load 1 domain O1 object and resave it with 1 field updated. (6) After f2 exit and execution point is back in f1() no commit done for O1 and no record data flushed to DB. Expected behavior is that after step 5 the nested transaction will be commited and hibernate session object O1 (modified within f2) call will be flushed and DB record updated.


Top
 Profile  
 
 Post subject: Re: bullshit JBoss JTA transactions with Hibernate persistan
PostPosted: Fri Jul 07, 2006 8:45 am 
Newbie

Joined: Tue Jul 04, 2006 9:58 am
Posts: 15
BTW why don't you try with Spring Framework. It's a relief b/c once you configured it you don't care about start/commit a transaction.

timasmith wrote:
I think I am fairly smart guy, but the transaction management in Hibernate with JBoss is ****** obscure.

On a side note I am sick, sick, sick to death of smart ass authors and online article gurus writing a few paragraphs on how to do xyz with 'snippets'. Read my lips:

POST A WORKING EXAMPLE (or get out of my google search results)

I have spent the entire day reading 'Hibernate in action' (or not in my case), online documentation, blogs, blurbs, forums and far fetched figures on how to configure transaction management with JBoss.

Yes I had a single 'insert' working, calling it multiple times with many readonly reads before and after.

No, I have never had the plain jane scenario work of:

a) start a session /transaction/ transaction on a session/ using JTA or not or JNDI or not

b) save (insert) a model

c) generate a failure

d) watch it all rollback

No, one transaction - not a problem. Multiple either my transaction has not successfully started, my session closed itself, the transaction was nested, some hidden AOP flip flop intercepted and crapped over my code,

I could post code, but its pointless - I could never do justice on all the combinations I have tried...

I feel JDBC generated code coming back into my vogue...

...unless someone can save me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 12:30 pm 
Beginner
Beginner

Joined: Thu Jun 15, 2006 5:31 am
Posts: 21
Spring? I never understand why everyone always assumes a web page. There is more to life than hacking a browser into an application platform... I am using Swing+RMI+J2EE+EJB3.0+Hibernate apps for a large enterprise level solution.

Anyway I finally got it to work with Jboss, JTA and HSQL though JTA broke when I switched to PostgreSQL and unfortunately I had to switch from JTA to JDBC in my transaction.factory_class

So not being a bastard here is a 'real' snippet for a distributed business object:

JBoss 4.0.4
EJB 3.0 Java 1.5.0.7
Hibernate3.jar that shipped with it 5/15/2006

public static void store(IBaseModel model, boolean continueSession) throws Exception {
try {
if (model.getId() == null) {
HibernateUtil.getSession().save(model);
} else {
IBaseModel original = (IBaseModel) load(model.getClass(),model.getId(),true);
model.copyModifiedTo(original);
HibernateUtil.getSession().save(original);
}
if (!continueSession) {
HibernateUtil.endSession();
}
} catch (Exception e) {
Log.warn(model);
HibernateUtil.rollbackSession();
throw e;
}
}


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.myproject.framework.logging.Log;

public class HibernateUtil {

private static Session currentSession = null;
private static SessionFactory sessionFactory = null;
private static Transaction transaction = null;

/**
* Configure the sessionFactory from hibernate.cfg.xml
*/
static {
try {
Configuration configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
} catch (Throwable ex) {
ex.printStackTrace(System.out);
ex.printStackTrace(System.err);
Log.fatal(ex);
System.exit(1);
}
}

/**
* Return the sessionFactory from cache
*
* @return
* @throws Exception
*/
private static SessionFactory getSessionFactory() throws Exception {
if (sessionFactory == null) {
throw new NullPointerException();
} else {
return sessionFactory;
}
}

/**
* Return the current session if it exists otherwise
* open a new session and start a new transaction
*
* @return
* @throws Exception
*/
public static Session getSession() throws Exception {
if (currentSession == null) {
currentSession = getSessionFactory().openSession();
if (currentSession == null) {
throw new NullPointerException();
}
transaction = currentSession.beginTransaction();
}
return currentSession;
}

/**
* Commit the transaction, rollback on error and close the session
*
* @throws Exception
*/
public static void endSession() throws Exception {
Session session = null;
try {
session = getSession();
transaction.commit();
} catch (Exception ex) {
Log.error(ex);
transaction.rollback();
} finally {
try {
session.close();
} catch (Exception ex2) {
Log.error(ex2);
} finally {
cleanup();
}
}
}

/**
* Remove the session and transaction from cache
*/
private static void cleanup() {
transaction = null;
currentSession = null;
}

/**
* Rollback the transaction and close the session
*
* @throws Exception
*/
public static void rollbackSession() {
try {
if (transaction != null) {
transaction.rollback();
}
} finally {
try {
Session session = getSession();
if (session != null) {
session.close();
}
} catch (Exception ex2) {
Log.error(ex2);
} finally {
cleanup();
}
}
}

}


package com.myproject.model.common;

public interface IBaseModel {

/**
* Unique database identifier
*
* @return
*/
public Long getId();

/**
* Copy all modified fields to the target model
*
* @param model
*/
public void copyModifiedTo(IBaseModel model);

}

hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="current_session_context_class">thread</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="hibernate.connection.username">patientis</property>
<property name="hibernate.connection.password">patientis</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="jta.UserTransaction">UserTransaction</property>

<mapping resource="com/patientis/model/patient/PatientModel.hbm.xml"/><mapping
resource="com/patientis/model/common/AddressModel.hbm.xml" />

</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 1:11 pm 
Newbie

Joined: Tue Jul 04, 2006 9:58 am
Posts: 15
I do not assume that it need to be a webpage. Spring is not only web framework and honestly we never use it's presentation API. I can witness that Hibernate works fine with JTA in JBoss container except PROPAGATION_NESTED semantic.
BTW i think using JDBC transactions doesn't make a big sense in multitired architecture where "long" transactions needed.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
he is using EJB3 and should be able to just use normal ejb3 persistencecontext's to manage his transactional boundaries.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 1:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...though i'm not sure if ejb3 supports nested transactions (haven't seen that anywhere....and i could also imagine it could give some "intersting" effects on a Session/PersistenceContext that spans multiple nested tx?)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 1:56 pm 
Beginner
Beginner

Joined: Thu Jun 15, 2006 5:31 am
Posts: 21
Thats crazy good I suppose. I guess you are referring to http://docs.jboss.org/ejb3/app-server/r ... rnate.html

though I repeat my thought on snippets.

The learning curve on Hibernate is not bad but the learning curve on JBoss+Hibernate+19 othertechnologiestomakeitallwork is steeeep.

I would give Max credits but he has too many so I'll give some to Yegor for his Spring tip.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 7:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so use seam ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 08, 2006 5:14 am 
Newbie

Joined: Tue Jul 04, 2006 9:58 am
Posts: 15
Well i don't think it make sense to check for nested trans in EJB specs. It does support it. But existing JTA impl in JBoss doesn't. Even if you take latest JBossTS with that arjuna stuff it doesn't really help. You'll get this: http://jira.jboss.com/jira/browse/JBAS-3364

max wrote:
...though i'm not sure if ejb3 supports nested transactions (haven't seen that anywhere....and i could also imagine it could give some "intersting" effects on a Session/PersistenceContext that spans multiple nested tx?)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 08, 2006 5:21 am 
Newbie

Joined: Tue Jul 04, 2006 9:58 am
Posts: 15
Haha! Max do you have any ideas how to avoid this http://jira.jboss.com/jira/browse/HIBERNATE-41
or this
http://jira.jboss.com/jira/browse/JBAS-3364
I would give any credits to anybody who can explain me what is wrong with the testcase described in HIBERNATE-41.
max wrote:
so use seam ,)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 08, 2006 6:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sorry no, i don't know the internals of our ejb tx stuff.

Sounds like a very good question to pose on the EJB3 forum or even getting support for.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.