Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JTA
JTA [message #918998] Fri, 21 September 2012 15:26 Go to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
I've setup Eclipselink using JTA (Bitronix) and appears to be working fine. Except one thing: no insert or update is executed on commit!

When my unit test does a BitronixTransactionManager.commit nothing is written to the database. However if I explicitly call an EM.flush before the commit, then the insert and update statements are executed. I have configured (TRANSACTION_TYPE,"JTA").

Am I missing something? (EL 2.4.0 @ J7)

Tom
Re: JTA [message #919169 is a reply to message #918998] Fri, 21 September 2012 18:55 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1023
Registered: July 2009
Senior Member
Looks like EclipseLink isn't registered for the before and after completion callbacks, have you created a JTATransactionController to allow EclipseLink to register for the callbacks with your TransactionManager? Since JTA is usually set through the server platform, you might need to write your own serverPlatform implementation to return a JTATransactionController instance that can look up your TransactionManager and register listeners to it. Check out the GlassfishPlatform and GlassfishTransactionController for server specific examples.

Best Regards,
Chris
Re: JTA [message #919638 is a reply to message #919169] Sat, 22 September 2012 06:51 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
On 2012-09-21 20:56, Chris Delahunt wrote:
> Looks like EclipseLink isn't registered for the before and after completion callbacks, have you created a JTATransactionController to allow EclipseLink to register for the callbacks with your TransactionManager? Since JTA is usually set through the server platform, you might need to write your own serverPlatform implementation to return a JTATransactionController instance that can look up your TransactionManager and register listeners to it. Check out the GlassfishPlatform and GlassfishTransactionController for server specific examples.

Below are my two classes:

public class EclipselinkBitronixServer extends ServerPlatformBase
{
public EclipselinkBitronixServer(DatabaseSession newDatabaseSession)
{
super(newDatabaseSession);
}

@SuppressWarnings("rawtypes")
@Override
public Class getExternalTransactionControllerClass()
{
if (externalTransactionControllerClass == null)
{
externalTransactionControllerClass = BitronixTransactionController.class;
}
return externalTransactionControllerClass;
}

@Override
protected void initializeServerNameAndVersion()
{
this.serverNameAndVersion = EclipselinkBitronixServer.class.getSimpleName();
}

}


public class BitronixTransactionController extends JTATransactionController
{
public BitronixTransactionController()
{
super();
}

@Override
protected TransactionManager acquireTransactionManager() throws Exception
{
TransactionManager lTransactionManager = bitronix.tm.TransactionManagerServices.getTransactionManager();
return lTransactionManager;
}
}


And this is the setup code:

Map<String, Object> lOptions = new HashMap<String, Object>();
lOptions.put(PersistenceUnitProperties.TRANSACTION_TYPE, "JTA");
lOptions.put(PersistenceUnitProperties.JTA_DATASOURCE, "java:comp/bm");
lOptions.put(PersistenceUnitProperties.TARGET_SERVER, EclipselinkBitronixServer.class.getName());
lOptions.put(PersistenceUnitProperties.NATIVE_SQL, "true"); // allow native SQL
lOptions.put(PersistenceUnitProperties.CACHE_STATEMENTS, "true"); // allow caching of statements
lOptions.put(PersistenceUnitProperties.UPPERCASE_COLUMN_NAMES, "true"); // uppercase all column names
lOptions.put(PersistenceUnitProperties.JOIN_EXISTING_TRANSACTION, "true"); // reads and write should go through the same connection
lOptions.put(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL , "true"); // this is deprecated, but the replacement CONNECTION_POOL_SEQUENCE does not work on 3.1.2-M1 // force sequences to use a separate pool, so rollback do not undo counter increments
lOptions.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, "false"); // do not use the shared cache (otherwise refresh will not update from db)
lOptions.put(PersistenceUnitProperties.ID_VALIDATION, null); // allow zero to be used as an @Id
final EntityManagerFactory lEntityManagerFactory = Persistence.createEntityManagerFactory("frozn", lOptions);
Re: JTA [message #923712 is a reply to message #919638] Wed, 26 September 2012 06:05 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
On 2012-09-22 08:52, tbee wrote:
> On 2012-09-21 20:56, Chris Delahunt wrote:
>> Looks like EclipseLink isn't registered for the before and after completion callbacks
>
> Below are my two classes:

Is it possible to check if the entity manager has attempted to register? How should I be looking for in the finest debug output?

Tom
Re: JTA - blog post [message #930834 is a reply to message #923712] Tue, 02 October 2012 17:30 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
I wrote a blog post about this.
http://tbeernot.wordpress.com/2012/10/02/stand-alone-business-model-with-activiti-eclipselink-and-unit-tests-on-postgresql/

The only remaining issue is the Eclipselink flush.

Tom
Re: JTA - blog post [message #930876 is a reply to message #930834] Tue, 02 October 2012 18:22 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1023
Registered: July 2009
Senior Member
Hello Tom,

Looks like you are getting an EntityManager outside of the transaction scope. You must call EntityManager.joinTransaction() to let it know there is an active transaction to register with.

Best Regards,
Chris
Re: JTA - blog post [message #930953 is a reply to message #930876] Tue, 02 October 2012 19:51 Go to previous message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
And the answer is so simple. Thank you!
Previous Topic:select records where elementcollection contains one of parameter list
Next Topic:JoinTable with additional column
Goto Forum:
  


Current Time: Sat Sep 20 00:08:22 GMT 2014

Powered by FUDForum. Page generated in 0.01936 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software