-->
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: CMT Session Bean
PostPosted: Mon Apr 19, 2004 11:24 pm 
Beginner
Beginner

Joined: Mon Sep 29, 2003 2:18 pm
Posts: 20
I have a Container-Managed Transaction Session Bean, and I was hoping I wouldn't have to do beginTransaction, etc. but let the container handle that.

My insert isn't working (it behaves as if I was using JSP not calling beginTransaction) but there are no exceptions.

Is it possible to do this? If not, that's fine, but one of my coworkers said this might be possible.

I'm using the transaction setup in jboss-service.xml that comes from the Hibernate/JBoss intro.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 11:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
This is most definietly possible. I do not know jboss, so I cannot speak to the specifics of its setup, but in general you simply need to point Hibernate at a datasource which is under the control of the TransactionManager managing the CMT transactions.

take a look at http://www.hibernate.org/hib_docs/reference/html/session-configuration.html#session-configuration-s4. Specifically the properties listed in Table 3.2


Top
 Profile  
 
 Post subject: Datasource
PostPosted: Tue Apr 20, 2004 12:52 am 
Beginner
Beginner

Joined: Mon Sep 29, 2003 2:18 pm
Posts: 20
I seem to be doing that, according to the setup I'm using:

<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=OracleDS</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">mappings/Modality.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/OracleDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.OracleDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>

Perhaps I just need to flush the session? Here's my code for getting the session:

package com.cti.resource;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;

public class HibernateUtil {

private static final String jndiName = "java:/hibernate/HibernateFactory";

private static final SessionFactory sessionFactory;

static {
try {
sessionFactory = (SessionFactory) new InitialContext().lookup(jndiName);
} catch (NamingException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}

public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 3:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, you need to flush the session manually in a CMT environment.


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.