|
|
Re: JTA [message #919638 is a reply to message #919169] |
Sat, 22 September 2012 06:51 |
Tom Eugelink Messages: 825 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);
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04085 seconds