-->
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.  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: transaction exception when using hibernate on WAS 6.0.2
PostPosted: Wed Dec 13, 2006 1:57 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
Hi,
I am getting problem with user transaction at the time server start. This problem is coming when hibernate session get closed. Details given below:-


Hibernate version: 3.2.0.cr3

Websphere version: 6.0.2

Mapping documents:
My Hibernate.cfg.xml looks as following:-
My SessionFactory configuration file looks as follows:
<session-factory>

<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>

<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>


</session-factory>




Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
[12/12/06 10:38:43:191 GMT] 0000003f Helpers W NMSV0610I: A NamingException is being thrown from a javax.naming.Context implementation. Details follow:
Context implementation: com.ibm.ws.naming.jndicos.CNContextImpl
Context method: lookupExt
Context name: HCLDSGMTP057Node01Cell/nodes/HCLDSGMTP057Node01/servers/server1
Target name: java:comp/UserTransaction
Other data: ""
Exception stack trace: javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: java
at com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext(CNContextImpl.java:3114)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1407)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:1290)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:144)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at org.hibernate.transaction.JTATransactionFactory.isTransactionInProgress(JTATransactionFactory.java:83)
at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:187)
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:159)
at org.hibernate.impl.SessionImpl.checkTransactionSynchStatus(SessionImpl.java:1861)
at org.hibernate.impl.SessionImpl.isOpen(SessionImpl.java:320)
at com.dixons.persistence.framework.server.HibernateSession.close(HibernateSession.java:158)
at com.dixons.persistence.framework.server.HibernateSession.finalize(HibernateSession.java:185)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java(Compiled Code))
at java.lang.ref.Finalizer.access$100(Finalizer.java(Inlined Compiled Code))
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java(Compiled Code))



Name and version of the database you are using:
Oracle 10

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Any help would be greatly appreciated, thanks in advance.
Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 9:32 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
What type of transaction management did you use, Bean-Managed Transactions or Container-Managed Transactions?

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 1:02 am 
Beginner
Beginner

Joined: Sat Nov 22, 2003 3:54 pm
Posts: 42
If you are using CMT , your hibernate factory class should be

org.hibernate.transaction.CMTTransactionFactory

instead of

org.hibernate.transaction.JTATransactionFactory

Cheers
Vijay


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 3:39 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
Thanks for your reply......

I am using bean managed transaction only. I am pasting below some extracts from the code for reference:-

public class HibernateUnitOfWork implements UnitOfWork {
public static Logger LOG = Logger.getLogger(HibernateUnitOfWork.class);

private static TransactionCallbackList list = new TransactionCallbackList();

private Transaction tx = null;
private HibernateSession session;
private RollbackOnlyMarker rollbackOnlyMarker;


private void createTransaction() throws PersistenceException {
if (LOG.isDebugEnabled()) {
LOG.debug("Hibernate.createTransaction() called.");
}
try {
this.tx = session.getSession().beginTransaction();
} catch (HibernateException e) {
throw new PersistenceException(
"Failed to construct UnitOfWork:" + e,
e);
}
}


public void close() throws PersistenceException {
if (LOG.isDebugEnabled()) {
LOG.debug("Hibernate.close().");
}
session.close();
}

.............

}



Also after the expception i am getting following warning messages when trying any transaction on the application:-

[17/12/06 22:54:48:549 GMT] 00000039 TranManagerIm E WTRN0017W: Unable to begin a nested transaction. Nested transactions are not supported.


Hope the above additional information would give you some more idea about the problem i am facing.....

Best Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 5:24 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
In code that you've posted, i didn't see the commit operation. Where you perform commit operation?

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 7:10 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
public void commit() throws PersistenceException {
if (LOG.isDebugEnabled()) {
LOG.debug("Hibernate.commit() called.");
}
checkForRollbackOnly();
try {

tx.commit();

} catch (HibernateException e) {
throw new PersistenceException("Commit failure:" + e, e);
} finally {
handleCallbacks();
// close the session to prevent it from being reused
// and dirty data being read from the session cache.
close();
}
}


the above methods are called on the object of HibernateUnitOfWork e.g. as following :-

UnitOfWork uow = new HibernateUnitOfWork(getConnection());
com.dixons.persistence.framework.server.domain.Test test = new com.dixons.persistence.framework.server.domain.Test();


long myId = theId++;

myIdThreadLocal.set(new Long(myId));

System.out.println("myId = " + myId);
test.setId(new Long(myId));
test.setDescription("LoadTest - Test insert");
uow.save(test);
uow.commit();


Best Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 8:49 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
Can you provide constructor for your HibernateUnitOfWork class? Also, where and how you use close() method of the HibernateUnitOfWork class?

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 1:44 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
public HibernateUnitOfWork(java.sql.Connection connection)
throws PersistenceException {
session = new HibernateSession(connection, FlushMode.COMMIT);
createTransaction();
if (LOG.isDebugEnabled()) {
LOG.debug("New HibernateUnitOfWork: " + connection.hashCode());
}
}


public HibernateSession(java.sql.Connection connection, FlushMode mode ) throws PersistenceException {
session = HibernateSessionFactory.getHibernateSession(connection);
session.setFlushMode(mode);
}

protected static org.hibernate.classic.Session getHibernateSession(java.sql.Connection connection) throws PersistenceException {

if (sf == null){
new HibernateSessionFactory();
}
if (connection == null){
throw new PersistenceException("A JDBC Connection must be provided");
} else {
return sf.openSession(connection);
}
}

private HibernateSessionFactory() throws PersistenceException {
initialise();
}

/**
* load configuration information
*/
private void initialise () throws PersistenceException {

try {
Configuration config = new Configuration().configure();
String value = config.getProperty("hibernate.interceptor");

// This will load the custom interceptor from the hibernate config file - using hibernates
// config loader.
try {
Interceptor interceptor = (Interceptor)getClass().getClassLoader().loadClass(value).newInstance();
config.setInterceptor(interceptor);
} catch (Exception e) {
// we simply ignore the interceptor and carry on...
}

sf = config.buildSessionFactory();

} catch (HibernateException e) {
throw new PersistenceException("Failed to construct HibernateSessionFactory:"+e, e);
}
}

The above code is called in sequence........hope this would provide you the required information....


Thanks & Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 1:48 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
Close() is getting called immigiately after commit().


Thanks & Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 5:20 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
Try to add jta.UserTransaction property to your Hibernate.cfg.xml file, like this:

<property name="jta.UserTransaction">
java:comp/UserTransaction
</property >


Also, can you provide your save() method of your HibernateUnitOfWork class?

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 7:33 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
public Serializable save(Object obj) throws PersistenceException {
if (LOG.isDebugEnabled()) {
logOperation("save", obj);
}
return session.save(obj);
}


public Serializable save(Object obj) throws PersistenceException {
return save(obj,false);
}

private Serializable save(Object obj, boolean forceSaveOnly) throws PersistenceException {
try {
if (immutable(obj)) {
return null;
} else {
if (forceSaveOnly){
session.save(obj);
} else {
session.saveOrUpdate(obj);
}

session.flush();
}
return session.getIdentifier(obj);
} catch (HibernateException e) {
e.printStackTrace();
//if (e.getThrowable(0) instanceof StaleConnectionException) throw e;
throw new PersistenceException("Failed to save object:" + obj, e);
}
}


I have included the property suggested by you, but still problem persist.


Thanks & Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 8:01 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
Try to use jta/usertransaction as the value of jta.UserTransaction property to your Hibernate.cfg.xml file, like this:

<property name="jta.UserTransaction">jta/usertransaction</property>

Can you describe your architecture? Where you use HibernateUnitOfWork class? In web container or may be in ejb container?

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 9:32 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
everything is runing inside the webcontainer only.....i will try the solution and will respond soon....

Thanks & Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 9:05 am 
Newbie

Joined: Wed Dec 13, 2006 1:27 am
Posts: 10
still problem persists....any other suggestion pls

Thanks and Regards
Amit Goel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 9:45 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
Ok. Can you try to get UserTransaction from JNDI manually, without Hibernate?

_________________
Best Regards


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