-->
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: Hibernate + JBoss container managed transactions
PostPosted: Tue Oct 14, 2003 2:03 pm 
Newbie

Joined: Tue Oct 14, 2003 1:52 pm
Posts: 3
Hi,

I'm using JBos + Hibernate. I want to know if it is possible to setup hibernate to automatically enroll the session in a container managed transaction. I have tried to set the <transaction-type> attribute in my ejb.jar to Container and comment out the session.beginTransaction() and tx.commit() but in this case no object goes into the DB.

Thanks.

========================
This is my code:

protected Session openNewSession()
throws MappingException, HibernateException, NamingException {
if (null == sessionFactory) {
InitialContext ctx = new InitialContext();
sessionFactory =
(SessionFactory) ctx.lookup(
"java:/hibernate/mfm/HibernateFactory");
}

Session session = sessionFactory.openSession();
return session;
}

Session session = null;
Device aDevice = null;
Transaction tx = null;
try {
session = openNewSession();
tx = session.beginTransaction();
aDevice = new Device(hardId, os, name);
session.save(aDevice);
tx.commit();
} catch (Exception hEx) {
hEx.printStackTrace();
if (tx != null)
try {
tx.rollback();
} catch (HibernateException e) {
throw new EJBException(e);
}
throw new EJBException(hEx);
} finally {
try {
if (null != session)
session.close();
} catch (HibernateException e1) {
e1.printStackTrace();
}
}

return aDevice;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 7:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is a FAQ. You must explicitly flush() the session.


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.