CodeWeblog.com » java code,inquiries,null return » Death linked to hibernate JNDI query WebSphere

Death linked to hibernate JNDI query WebSphere

Operating Environment:
Aix + WebSphere 6.1 + Oracle + Quartz1.65 + Sping2.5.6 + Hibernate 3.3.1
Phenomenon:
Node & Server of WebSphere hanging dead, JVM stack overflow, WebSphere district where the JVM core dump file to be filled
Reasons:
Quartz managed threads running in a state of non-container hosting (from WebSphere control), access to less than a J2EE context, and the use of threads to Hibernete, in trying to java: comp / UserTransaction when JTA inquiries throw NamingException, and Hibernete JTATransactionFactory. the existence of the following java code BUG:
	protected UserTransaction getUserTransaction() {
		log.trace( "Attempting to locate UserTransaction via JNDI [{}]", getUserTransactionName() );

		try {
			UserTransaction ut = ( UserTransaction ) getInitialContext().lookup( getUserTransactionName() );
			if ( ut == null ) {
				throw new TransactionException( "Naming service lookup for UserTransaction returned null [" + getUserTransactionName() +"]" );
			}

			log.trace( "Obtained UserTransaction" );

			return ut;
		}
		catch ( NamingException ne ) {
			throw new TransactionException( "Could not find UserTransaction in JNDI [" + getUserTransaction() + "]", ne );
		}
	}

Which throw new TransactionException ( "Could not find UserTransaction in JNDI [" + getUserTransaction () + "]", according to the author's meaning should be getUserTransactionName () mistakenly written the getUserTransaction () lead to infinite recursive calls

Solutions:
Option 1:
JTATransactionFactory.java rewrite the getUserTransaction () method
Code is as follows
protected UserTransaction getUserTransaction() {
		log.trace( "Attempting to locate UserTransaction via JNDI [{}]", getUserTransactionName() );
		if(uTran != null)
			return uTran;
		try {
			uTran = ( UserTransaction ) getInitialContext().lookup( getUserTransactionName() );
			if ( uTran == null ) {
				uTran = ( UserTransaction ) getInitialContext().lookup( CLIENT_USER_TRANSACTION_NAME );
				if(uTran != null)
					return uTran;
				else
				throw new TransactionException( "Naming service lookup for UserTransaction returned null [" + getUserTransactionName() +"]" );
			}

			log.trace( "Obtained UserTransaction" );

			return uTran;
		}
		catch ( NamingException ne ) {
			try {
				uTran = ( UserTransaction ) getInitialContext().lookup( CLIENT_USER_TRANSACTION_NAME );
			} catch (NamingException e) {
				e.printStackTrace();
			}
			if(uTran != null)
				return uTran;
			else
			throw new TransactionException( "Could not find UserTransaction in JNDI [" + getUserTransactionName() + "]", ne );
		}
	}


Which CLIENT_USER_TRANSACTION_NAME = "jta / usertransaction"

Option 2:
Custom category hibernate.transaction.factory_class
Spring into the use of usertransaction
Heavy getUserTransaction
 protected UserTransaction getUserTransaction() {
    return userTransaction;
   }
Digg Technorati StumbleUpon Mixx del.icio.us Reddit BlinkList Furl YahooMyWeb feedburner

Tags: java code (RSS), inquiries (RSS), null return (RSS), amp (RSS), oracle (RSS), existence (RSS), operating environment (RSS), phenomenon (RSS), threads (RSS), stack overflow (RSS), naming service (RSS), option 1 (RSS), thr (RSS), quartz (RSS), utran (RSS)

Permalink: http://www.codeweblog.com/death-linked-to-hibernate-jndi-query-websphere/

Leave a reply