-->
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.  [ 9 posts ] 
Author Message
 Post subject: using hibernate with ejb2 session beans
PostPosted: Mon Feb 06, 2006 2:05 am 
Newbie

Joined: Fri Feb 03, 2006 1:40 am
Posts: 11
Can someone please point to some references/sample code for acheiving the following using hibernate ?

1. one time creation of hibernate session factory in the context of app servers.
2. when/how to make hiberbate session use underlying connections/transaction context.

I basically want to setup using Hibernate with session beans. (ejb2.x)

Thank You.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 2:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Using JBoss - setup the session using an MBean or sar deployment package - see JBoss wiki or there is some info on the Hibernate wiki. This works well and is how I do it normally. You could use the HibernateUtil package to configure your session factory in a static.

During the SLSB method call get the session from the deployed factory and then go for your life.

Maybe worth having a look at the sample (such as for HIA [There is one for H2 and H3 which are quite different] and others).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 1:41 pm 
Newbie

Joined: Fri Feb 03, 2006 1:40 am
Posts: 11
I am using Hibernate 3.1 in a J2EE context. (EJB2.x)

I have the following configuration in hibernate.cfg.xml

<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.WeblogicTransactionManagerLookup
</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.CMTTransactionFactory
</property>


However when I perform SessionFactory.getCurrentSession() I get the following exception:

org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:604)

Result is the same when I use "org.hibernate.transaction.JTATransactionFactory" instead of "CMTTransactionFactory" in the configuration.

I am using a stateless session bean that is configured with "transaction-type" = Container in the deployment descriptor.

Any help will be appreciated.

Thank You


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 2:56 pm 
Newbie

Joined: Fri Feb 03, 2006 1:40 am
Posts: 11
I got it working by setting the container-transaction element in
the deployment descriptor

<container-transaction >
<method >
<ejb-name>Test</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>

Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 6:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Glad you were able to sort it out. Yes CMT is the way to go.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 3:41 am 
Newbie

Joined: Thu May 18, 2006 4:31 am
Posts: 12
Location: Germany
balamg wrote:
I got it working by setting the container-transaction element in
the deployment descriptor

<container-transaction >
<method >
<ejb-name>Test</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>

Thanks !


Hello!
I see this is a solution, but imo not a preferred one. For every readonly-access to the DB a new transaction has to be started.
I don't know how deep the performance impact will be (Oracle 8.1.7) but I'm not very happy about setting for each method the transaction-attribute to "Required".

Is this really the only non-programmatic / configurable solution??

Jan


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 2:29 am 
Newbie

Joined: Fri Feb 03, 2006 1:40 am
Posts: 11
As per my understanding, hibernate runs inside the context of an underlying transaction hence if one decides to use bean managed transaction, its still fine as long as the hibernate calls are made after the transaction has been started.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 3:15 am 
Newbie

Joined: Thu May 18, 2006 4:31 am
Posts: 12
Location: Germany
Hi balamg,

but you do also use Container managed transaction, and not Bean MT, don't you?
And for this case, setting the transaction-type to "Required" is your only solution?!
I will also use "Required" for each method, as I don't find another way to get it work...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 4:54 am 
Newbie

Joined: Fri Feb 03, 2006 1:40 am
Posts: 11
Yes, I am using CMT.


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