Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365704

Summary: JNDI location for JBoss Transaction Manager is wrong
Product: z_Archived Reporter: fountain2012
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P2 CC: andrei.ilitchev, michael.f.obrien, ringerc, scott.marlow, smarlow, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard: submitted_patch
Bug Depends on:    
Bug Blocks: 383201    
Attachments:
Description Flags
screen shot of JNDI mapping in Jboss 7.0.2 final showing transactionmanager
none
stack trace
none
Look for AS7 TM and then AS4 (through 6) TM
none
Previous patch - slightly updated
none
Test case showing problem may not be fixed in 2.4.0-RC2 and 2.3.3-M3
none
Log of execution of ExplicitClassesTest.isTransactional() on 7.1.1.Final against 2.4.0-RC2
none
Exception produced when transactional operation fails
none
Log of execution of ExplicitClassesTest.isTransactional() on 7.1.1.Final against 2.4.0-RC2
none
ExplicitClassesTest.isTransactional() only, with TRACE for com.arjuna
none
ExplicitClassesTest.isTransactional() only, with TRACE for com.arjuna
none
ExplicitClassesAndTxWorkaroundTest.isTransactional() with com.arjuna TRACE none

Description fountain2012 CLA 2011-12-06 05:57:24 EST
Build Identifier: eclipselink-2.3.1.v20111018-r10243

Environment:
Jboss 7.0.2 Final
eclipselink-2.3.1.v20111018-r10243

I get the following exception when I call persist on EntityManager. I am using JTA.

15:19:59,799 INFO  [stdout] (http--127.0.0.1-8080-2) Exception Description: Error looking up external Transaction resource under JNDI name [java:/TransactionManager]

I checked the code for:
org.eclipse.persistence.transaction.jboss.JBossTransactionController 

this class contains a line:
public static final String JNDI_TRANSACTION_MANAGER_NAME = "java:/TransactionManager";

this is wrong. it should be.

public static final String JNDI_TRANSACTION_MANAGER_NAME = "java:jboss/TransactionManager";

please see the attached image and stack-trace.


Reproducible: Always

Steps to Reproduce:
1.create a JPA application using eclipselink-2.3.1.v20111018-r10243
2.create an entity
3.create a session bean that has a method that calls persist method on EntityManager
4.deploy to Jboss 7.0.2 Final
5.start server and call the session bean method.
Comment 1 fountain2012 CLA 2011-12-06 05:58:44 EST
Created attachment 207966 [details]
screen shot of JNDI mapping in Jboss 7.0.2 final showing transactionmanager
Comment 2 fountain2012 CLA 2011-12-06 05:59:17 EST
Created attachment 207967 [details]
stack trace
Comment 3 Tom Ware CLA 2011-12-15 07:49:11 EST
You should be able to workaround this by subclassing org.eclipse.persistence.platform.server.jboss.JBossPlatform

and

org.eclipse.persistence.transaction.jboss.JBossTransactionController

In JBossTransactionController change the acquireTransactionManager() method to lookup the alternate location.

In JBossPlatform, change getExternalTransactionControllerClass() to return your new Transaction controller.

You can tell your persistence unit to use these new classes by specifying the eclipselink.target-server persistence unit property with the classname of your new TransactionController as the value.
Comment 4 Tom Ware CLA 2011-12-22 10:36:39 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 5 Scott Marlow CLA 2012-02-15 21:16:09 EST
Created attachment 211082 [details]
Look for AS7 TM and then AS4 (through 6) TM
Comment 6 Scott Marlow CLA 2012-02-16 09:40:40 EST
I generated the attached patch from svn://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk.  

If I change into foundation/org.eclipse.persistence.core, I can build with maven successfully.  I would like to test the patch more completely, do I need to just build the other foundation folders with maven?  

The instructions on http://wiki.eclipse.org/EclipseLink/Development/TestStatus/MOXy-Instructions didn't seem to work for me and accessing the linked EclipseLink forum gave a blank browser page (perhaps a temporary issue).
Comment 7 Scott Marlow CLA 2012-02-17 07:04:28 EST
Seems to be building from dev root folder now ("ant -f  antbuild.xml").
Comment 8 Andrei Ilitchev CLA 2012-04-02 16:27:21 EDT
Created attachment 213470 [details]
Previous patch - slightly updated

Try AS4 only in case of JNDI lookup Namimg exception (wrapped into TransactionException).
Comment 9 Andrei Ilitchev CLA 2012-04-02 16:35:19 EDT
Checked the patch into both trunk (2.4) and 2.3.3.
Comment 10 Craig Ringer CLA 2012-06-19 09:40:26 EDT
Implemementing Tom Ware's approach, the following is tested and works:



import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.TransactionManager;

import org.eclipse.persistence.platform.server.jboss.JBossPlatform;
import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.transaction.jboss.JBossTransactionController;

public class JBossAS7ServerPlatform extends JBossPlatform {

	public JBossAS7ServerPlatform(DatabaseSession newDatabaseSession) {
		super(newDatabaseSession);
	}
	
	@Override
	public Class<?> getExternalTransactionControllerClass() {
		return JBossAS7TransactionController.class;
	}
	
	public static class JBossAS7TransactionController extends JBossTransactionController {
		@Override
		protected TransactionManager acquireTransactionManager() {
			try {
				return InitialContext.doLookup("java:jboss/TransactionManager");
			} catch (NamingException ex) {
				throw new UnsupportedOperationException("Couldn't get transaction manager");
			}
		}
	}

}


If you want to support older servers, you'll want to handle the NamingException more gracefully, but for me this is just a stopgap until 2.4 / 2.3.3 .
Comment 11 Craig Ringer CLA 2012-06-19 19:48:01 EDT
Please consider adding jbossas7 to keywords. I'd do it, but don't have the access rights.
Comment 12 Tom Ware CLA 2012-06-20 09:15:22 EDT
With the checked in change, the JBoss keyword will cover AS9.
Comment 13 Scott Marlow CLA 2012-06-20 10:06:16 EDT
(In reply to comment #12)
> With the checked in change, the JBoss keyword will cover AS9.

We haven't started to develop AS9 yet but am hoping that EclipseLink will switch to using the TransactionSynchronizationRegistry (TSR) instead of TransactionManager (TM) by then.  Would be nice to see an EclipseLink patch show up for switching to the TSR.  :)

There is some discussion here http://java.net/projects/jpa-spec/lists/jsr338-experts/archive/2011-10/message/3 about introducing a standard way of looking up the TransactionManager which was rejected since the TransactionSynchronizationRegistry is supposed to be used instead (with EE servers).  

Scott
Comment 14 Craig Ringer CLA 2012-06-21 05:12:27 EDT
I've just tested this with 2.4.0-RC2 and 2.3.3-M3 . In both cases an explicit "eclipselink.target-server" and adapter is still required for correct TransactionManager lookup.

An Arquillian testcase that demonstrates this issue will be attached. The test uses a workaround for another issue where classes appear to have to be explicitly listed not discovered by <exclude-unlisted-classes>false</exclude-unlisted-classes>.

Do you know what revision fixed this? The change was committed in April, so I'd expect it to be in the above releases.
Comment 15 Craig Ringer CLA 2012-06-21 05:17:53 EDT
Created attachment 217678 [details]
Test case showing problem may not be fixed in 2.4.0-RC2 and 2.3.3-M3

Test case attached. See README in the archive and the code comments for details.
Comment 16 Andrei Ilitchev CLA 2012-06-21 09:17:33 EDT
Could you please attach server log with the exception you are getting.
Comment 17 Craig Ringer CLA 2012-06-21 11:10:52 EDT
Created attachment 217700 [details]
Log of execution of ExplicitClassesTest.isTransactional() on 7.1.1.Final against 2.4.0-RC2

As requested, here's a log from the test run. To produce it, I:

- Stopped AS7

- Installed the EclipseLink module

- edited standalone/configuration/standalone.xml and in <subsystem 
xmlns="urn:jboss:domain:logging:1.1"> set:

            <logger category="org.eclipse.persistence">
                <level name="TRACE"/>
            </logger>
            <logger category="org.jboss.as.jpa">
                <level name="TRACE"/>
            </logger>

- Started AS7

- Edited the test case to add @Ignore to ExplicitClassesAndTxWorkaroundTest and NoWorkaroundsTest and all test methods of ExplicitClassesTest other than isTransactional(), to reduce log spew and keep the test focused.

- Quickly updated the test to integrate EclipseLink logging with JBoss logging using a de-Guava-ized version of the integration code in https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7 . This just makes the logs readable. I'll attach a new testcase with improved logging soon.

- Ran "mvn clean test"

- Attached the as7 log
Comment 18 Craig Ringer CLA 2012-06-21 11:22:19 EDT
Created attachment 217702 [details]
Exception produced when transactional operation fails

The updated testcase with logging integration is here:

https://github.com/ringerc/scrapcode/tree/master/testcases/javaee/JBossAS7-EclipseLink-Module/as7.eclipselink
Comment 19 Craig Ringer CLA 2012-06-21 11:23:12 EDT
Created attachment 217703 [details]
Log of execution of ExplicitClassesTest.isTransactional() on 7.1.1.Final against 2.4.0-RC2

Sorry, accidentally set application/gzip for encoding on first log upload. Fixed.
Comment 20 Scott Marlow CLA 2012-06-21 11:37:21 EDT
Craig,

Could you also enable TRACE logging for the AS7 JBoss TM?

<logger category="com.arjuna">
        <level name="TRACE" />
</logger>

It would be nice to see the output of that also.

Thanks!
Comment 21 Craig Ringer CLA 2012-06-21 12:10:01 EDT
Created attachment 217711 [details]
ExplicitClassesTest.isTransactional() only, with TRACE for com.arjuna

As requested, test re-run with TRACE level for com.arjuna.
Comment 22 Craig Ringer CLA 2012-06-21 12:14:46 EDT
Created attachment 217712 [details]
ExplicitClassesTest.isTransactional() only, with TRACE for com.arjuna
Comment 23 Craig Ringer CLA 2012-06-21 12:20:19 EDT
Created attachment 217713 [details]
ExplicitClassesAndTxWorkaroundTest.isTransactional() with com.arjuna TRACE

Also added a log for the same test run with the custom JBossAS7ServerPlatform visible and activated in persistence.xml. Test succeeds.
Comment 24 Craig Ringer CLA 2012-06-21 12:26:15 EDT
After discussion elsewhere, I've found that explicitly setting                         

<property name="eclipselink.target-server" value="jboss"/>

allows the test to pass, so this isn't the same bug. If you tell EclipseLink it's on JBoss it now (as of 2.4.0 and 2.3.3) finds the tx manager correctly.

The issue is thus not that EclipseLink is using the wrong tx manager path on JBoss, but that it isn't detecting AS7 and enabling the correct integration.

This bug is indeed RESOLVED FIXED, but another one is needed.
Comment 25 Scott Marlow CLA 2012-06-21 13:05:45 EDT
My vote would be to add integration code to AS7 that automatically passes the
<property name="eclipselink.target-server" value="jboss"/> in on the
PersistenceProvider.createContainerEntityManagerFactory call (which requires
adding an integration adapter for EclipseLink to AS7).  

If someone wants to contribute a patch for that, I'll work with them.  We could
discuss on https://community.jboss.org/en/jbossas7/dev.  If no one volunteers,
I can do it sometime.
Comment 26 Tom Ware CLA 2012-06-21 13:06:43 EDT
FYI: EclipseLink currently does not detect the server for any server.  Please
feel free to file an enhancement request for this functionality and provide any suggestions/patches you have.
Comment 27 Craig Ringer CLA 2012-06-21 13:16:26 EDT
Scott: Sorry for the wasted time. I *did* post a complete test case that showed persistence.xml (and no eclipselink.target-server = jboss ) so the info was there, but the absence of a line in a testcase doesn't exactly leap out at the reader. Sorry for the confusion.
Comment 28 Eclipse Webmaster CLA 2022-06-09 10:26:45 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink