Re: Propblem with OpenEJB + Toplink unit tests

2008-08-04 Thread David Blevins


On Aug 4, 2008, at 2:49 AM, Marcin Kwapisz wrote:


Hi,

Configuration: OpenEJB 3.0, ToplinkEssentials 2.1, Maven2, JUnit 4,  
Derby 10.2.2


I have modified that example - 
http://openejb.apache.org/3.0/testing-transactions-example.html
to use Toplink as persistence provider. The problem is, that Toplink  
does not persists entities at all. With OpenJPA or Hibernate all  
work fine.


As You may see below, sequences are updated properly.

[TopLink Finest]: 2008.08.04 11:17:31.359--ServerSession(13948523)-- 
Thread(Thread[main,5,main])--end deploying Persistence Unit barPU;  
state Deployed; factoryCount 1
[TopLink Finer]: 2008.08.04 11:17:31.406--ServerSession(13948523)-- 
Thread(Thread[main,5,main])--client acquired
[TopLink Finest]: 2008.08.04 11:17:31.406--UnitOfWork(19780920)-- 
Thread(Thread[main,5,main])--Execute query DoesExistQuery()
[TopLink Finest]: 2008.08.04 11:17:31.406--UnitOfWork(19780920)-- 
Thread(Thread[main,5,main])--PERSIST operation called on:  
pl.zsk.samples.ejbaccess.entities.Person[id=null;Marcin].
[TopLink Finest]: 2008.08.04 11:17:31.406--ClientSession(9876930)-- 
Thread(Thread[main,5,main])--Execute query DataModifyQuery()
[TopLink Finest]: 2008.08.04 11:17:31.406--ClientSession(9876930)-- 
Thread(Thread[main,5,main])--reconnecting to external connection pool
[TopLink Fine]: 2008.08.04 11:17:31.406--ClientSession(9876930)-- 
Connection(7789321)--Thread(Thread[main,5,main])--UPDATE SEQUENCE  
SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?

   bind = [50, PERSONENT]
[TopLink Finest]: 2008.08.04 11:17:31.421--ClientSession(9876930)-- 
Thread(Thread[main,5,main])--Execute query ValueReadQuery()
[TopLink Fine]: 2008.08.04 11:17:31.421--ClientSession(9876930)-- 
Connection(7789321)--Thread(Thread[main,5,main])--SELECT SEQ_COUNT  
FROM SEQUENCE WHERE SEQ_NAME = ?

   bind = [PERSONENT]
[TopLink Finest]: 2008.08.04 11:17:31.421--ClientSession(9876930)-- 
Connection(7789321)--Thread(Thread[main,5,main])--local sequencing  
preallocation for PERSONENT: objects: 50 , first: 1, last: 50
[TopLink Finest]: 2008.08.04 11:17:31.421--UnitOfWork(19780920)-- 
Thread(Thread[main,5,main])--assign sequence to the object (1 -  
pl.zsk.samples.ejbaccess.entities.Person[id=null;Marcin])
2008-08-04 11:17:31 pl.zsk.samples.ejbservice.AccountEntBeanTest  
testCreatePersonEnt

INFO: Get Persons from Database.
[TopLink Finest]: 2008.08.04 11:17:31.531--UnitOfWork(19780920)-- 
Thread(Thread[main,5,main])--Execute query  
ReportQuery(pl.zsk.samples.entities.PersonEnt)
[TopLink Finest]: 2008.08.04 11:17:31.546--ServerSession(13948523)-- 
Thread(Thread[main,5,main])--reconnecting to external connection pool
[TopLink Fine]: 2008.08.04 11:17:31.546--ServerSession(13948523)-- 
Connection(13305839)--Thread(Thread[main,5,main])--SELECT ID,  
FIRSTNAME, LASTNAME FROM PERSONENT

[]
2008-08-04 11:17:31 pl.zsk.samples.ejbservice.AccountEntBeanTest  
testCreatePersonEnt

INFO: []

When I call flush just after persist I get the EJBException:

javax.ejb.EJBException: The bean encountered a non-application  
exception.; nested exception is:
   javax.ejb.EJBTransactionRolledbackException: The transaction  
has been marked rollback only because the bean encountered a non- 
application  
exception :javax.persistence.TransactionRequiredException :

Exception Description: No transaction is currently active

This is strange. Why transaction does not begin? Any suggestions how  
to configure Toplink to make it work.

Thanks in advance


It may be that TopLink doesn't know how to find our  
TransactionManager.  OpenJPA finds it automatically by calling  
org.apache.openejb.OpenEJB.getTransactionManager().  For Hibernate,  
there's the TransactionManagerLookup which can be configured.  Do you  
know if there's anything similar in TopLink?


-David



RE: Propblem with OpenEJB + Toplink unit tests

2008-08-04 Thread Marcin Kwapisz
 It may be that TopLink doesn't know how to find our
 TransactionManager.  OpenJPA finds it automatically by calling
 org.apache.openejb.OpenEJB.getTransactionManager().  For Hibernate,
 there's the TransactionManagerLookup which can be configured.  Do you
 know if there's anything similar in TopLink?
 
[Marcin Kwapisz] 
Thanks David for the hint.

There is such feature and similar problem (solution also) is described here:
http://forums.oracle.com/forums/thread.jspa?threadID=625250tstart=0messageID=2390496
and here:
http://www.jroller.com/guruwons/entry/use_glassfish_java_persistence_provider

The only one thing I had to find was TransactionManager jndi name: 
java:comp/TransactionManager

public class OpenEJBTransactionController extends JTATransactionController
{

public static final String JNDI_TRANSACTION_MANAGER_NAME = 
java:comp/TransactionManager;

public OpenEJBTransactionController()
{
super();
}

@Override
protected TransactionManager acquireTransactionManager() throws Exception
{
return (TransactionManager) jndiLookup(JNDI_TRANSACTION_MANAGER_NAME);
}
}

and in persistence.xml

property name=toplink.target-server 
value=pl.zsk.samples.ejbservice.OpenEJBTransactionController/

Regards
-- 
Marcin Kwapisz
Division of Computer Networks
Technical Univeristy of Lodz, Poland



Re: Propblem with OpenEJB + Toplink unit tests

2008-08-04 Thread David Blevins


On Aug 4, 2008, at 5:45 AM, Marcin Kwapisz wrote:


It may be that TopLink doesn't know how to find our
TransactionManager.  OpenJPA finds it automatically by calling
org.apache.openejb.OpenEJB.getTransactionManager().  For Hibernate,
there's the TransactionManagerLookup which can be configured.  Do you
know if there's anything similar in TopLink?


[Marcin Kwapisz]
Thanks David for the hint.

There is such feature and similar problem (solution also) is  
described here:

http://forums.oracle.com/forums/thread.jspa?threadID=625250tstart=0messageID=2390496
and here:
http://www.jroller.com/guruwons/entry/use_glassfish_java_persistence_provider

The only one thing I had to find was TransactionManager jndi name:  
java:comp/TransactionManager


public class OpenEJBTransactionController extends  
JTATransactionController

{

   public static final String JNDI_TRANSACTION_MANAGER_NAME =  
java:comp/TransactionManager;


   public OpenEJBTransactionController()
   {
   super();
   }

   @Override
   protected TransactionManager acquireTransactionManager() throws  
Exception

   {
   return (TransactionManager)  
jndiLookup(JNDI_TRANSACTION_MANAGER_NAME);

   }
}

and in persistence.xml

property name=toplink.target-server  
value=pl.zsk.samples.ejbservice.OpenEJBTransactionController/


Fantastic, thank you!

Added some features for you and other TopLink/EclipseLink users.  We  
now generate an implement of JTATransactionController and will  
automatically set the target-server property if we determine you are  
using the TopLink or EclipseLink providers.


http://issues.apache.org/jira/browse/OPENEJB-880
http://issues.apache.org/jira/browse/OPENEJB-881

So when 3.1 comes out, you shouldn't need to set the toplink.target- 
server property anymore and will be able to dump your custom  
OpenEJBTransactionController, though it will continue to work if you  
want to use it (i.e. we won't override the property if we see you've  
set it to a custom class).


Sort of a conceptual copy of what we did for hibernate:  
http://issues.apache.org/jira/browse/OPENEJB-801


-David




Re: Propblem with OpenEJB + Toplink unit tests

2008-08-04 Thread David Blevins

Marcin,

Do you happen to know what the TopLink property is for automatically  
creating all the required tables?


In OpenJPA it's:
  property name=openjpa.jdbc.SynchronizeMappings  
value=buildSchema(ForeignKeys=true)/


In Hibernate it's:
  property name=hibernate.hbm2ddl.auto value=create-drop/


-David