openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pinaki Poddar" <ppod...@bea.com>
Subject RE: OpenJPA & Transaction configuration
Date Thu, 01 Mar 2007 03:33:56 GMT
  instead of _em.persist(ret);
try
  _em.merge(ret);

as ret is detached instance rather than new.



Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: Matthieu Riou [mailto:matthieu.riou@gmail.com] 
Sent: Wednesday, February 28, 2007 6:29 PM
To: open-jpa-dev@incubator.apache.org
Subject: OpenJPA & Transaction configuration

Hi,

I'm going back at the OpenJPA implementation for the Apache ODE project
and am still having problems with the setup. Whan I try to persist a new
object I get an exception "Attempt to persist detached object". I guess
the when I instantiate my object OpenJPA can't locate its transactional
context or something related therefore assuming that the object is
instantiated outside of any persistent context.

Here is the code that creates the EntityManagerFactory:

        HashMap<String, Object> propMap = new HashMap<String,Object>();
        propMap.put("openjpa.Log", "DefaultLevel=TRACE");
        propMap.put("openjpa.jdbc.DBDictionary", "
org.apache.openjpa.jdbc.sql.DerbyDictionary");
        propMap.put("openjpa.ManagedRuntime", new TxMgrProvider());
        propMap.put("openjpa.ConnectionFactory", _ds);
        propMap.put("openjpa.ConnectionFactoryMode", "managed");
        propMap.put("openjpa.Log", "DefaultLevel=TRACE");
        _emf = Persistence.createEntityManagerFactory("ode-dao",
propMap);

And here is my object instantiation code:

        ProcessDAOImpl ret = new
ProcessDAOImpl(pid,type,guid,this,version);
        System.out.println("detached " +
((PersistenceCapable)ret).pcIsDetached());
        _em.persist(ret);

My little debugging statement outputs "true". I've reproduced the full
log below. I've also encapsulated to transaction manager and the
transaction to check whether OpenJPA was getting the transaction and
registering a synchronizer properly. It seems to be doing so (the log
statements are just a couple lines above the '.....'). I've removed all
the mapping logs just to avoid making this too lengthy.

Any idea of what the problem could be? I'm kind of stuck on this as it's
hard to debug the enhanced code that gets called when I instantiate my
process object.

DEBUG - ODEMessageReceiver.receive(47) | Received message for
helloWorld.hello DEBUG - ODEService.onAxisMessageExchange(96) | Starting
transaction.
DEBUG - BpelEngineImpl.route(237) | Routed: svcQname {
http://ode/bpel/unit-test.wsdl}HelloService --> BpelProcess[{
http://ode/bpel/unit-test}HelloWorld2-1]
29603  ode-dao  INFO   [http-8080-Processor25] openjpa.Runtime -
Starting
OpenJPA 0.9.7-incubating-SNAPSHOT
29604  ode-dao  TRACE  [http-8080-Processor25] openjpa.Runtime -
Properties:
openjpa.EntityManagerFactory: default
openjpa.DataCache: false
openjpa.MetaDataFactory: jpa(Types=
org.apache.ode.dao.jpa.ActivityRecoveryDAOImpl
;org.apache.ode.dao.jpa.CorrelationSetDAOImpl;org.apache.ode.dao.jpa.Cor
relatorDAOImpl;org.apache.ode.dao.jpa.EventDAOImpl;org.apache.ode.dao.jp
a.FaultDAOImpl;org.apache.ode.dao.jpa.MessageDAOImpl;org.apache.ode.dao.
jpa.MessageExchangeDAOImpl;org.apache.ode.dao.jpa.MessageRouteDAOImpl;or
g.apache.ode.dao.jpa.PartnerLinkDAOImpl;org.apache.ode.dao.jpa.ProcessDA
OImpl;org.apache.ode.dao.jpa.ProcessInstanceDAOImpl;org.apache.ode.dao.j
pa.ScopeDAOImpl;org.apache.ode.dao.jpa.XmlDataDAOImpl)
openjpa.InverseManager: false
openjpa.ReadLockLevel: read
openjpa.DataCacheManager: default
openjpa.jdbc.SubclassFetchMode: join
openjpa.jdbc.UpdateManager: default
openjpa.jdbc.SynchronizeMappings: false
openjpa.NontransactionalRead: true
openjpa.QueryCompilationCache: true
openjpa.MaxFetchDepth: -1
openjpa.RetainState: true
openjpa.DynamicDataStructs: false
openjpa.BrokerFactory: jdbc
openjpa.WriteLockLevel: write
openjpa.ManagedRuntime:
org.apache.ode.dao.jpa.BPELDAOConnectionFactoryImpl$TxMgrProvider
openjpa.jdbc.EagerFetchMode: parallel
openjpa.RestoreState: immutable
openjpa.jdbc.SchemaFactory: dynamic
openjpa.LockManager: version
openjpa.BrokerImpl: default
openjpa.NontransactionalWrite: true
openjpa.MetaDataRepository: default
openjpa.Log: true(DefaultLevel=TRACE)
openjpa.jdbc.ResultSetType: forward-only
openjpa.AutoDetach:
openjpa.ConnectionRetainMode: on-demand
openjpa.SavepointManager: in-mem
openjpa.jdbc.DBDictionary: derby
openjpa.Optimistic: true
openjpa.ConnectionFactoryMode: managed
openjpa.Sequence: table
openjpa.FetchGroups: default
openjpa.jdbc.Schemas:
openjpa.Id: ode-dao
openjpa.OrphanedKeyAction: log
openjpa.FlushBeforeQueries: true
openjpa.AutoClear: datastore
openjpa.Compatibility: default
openjpa.DetachState: loaded
openjpa.jdbc.LRSSize: query
openjpa.Multithreaded: false
openjpa.FetchBatchSize: -1
openjpa.jdbc.SQLFactory: default
openjpa.IgnoreChanges: false
openjpa.jdbc.MappingDefaults: jpa
openjpa.TransactionMode: local
openjpa.RetryClassRegistration: false
openjpa.jdbc.FetchDirection: forward
openjpa.ClassResolver: default
openjpa.LockTimeout: -1
openjpa.DataCacheTimeout: -1
openjpa.QueryCache: true
openjpa.jdbc.DriverDataSource: simple
openjpa.jdbc.TransactionIsolation: default
openjpa.ProxyManager: default
29604  ode-dao  TRACE  [http-8080-Processor25] openjpa.MetaData - Using
metadata factory "
org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1742ad8".
29604  ode-dao  INFO   [http-8080-Processor25] openjpa.jdbc.JDBC - Using
dictionary class "org.apache.openjpa.jdbc.sql.DerbyDictionary".
WARN - BPELDAOConnectionFactoryImpl$DebugTxMgr.getTransaction(130) | JPA
get transaction WARN -
BPELDAOConnectionFactoryImpl$DebugTx.registerSynchronization(179) |
Synchronization registration on org.apache.openjpa.kernel.BrokerImpl
WARN - BPELDAOConnectionFactoryImpl$DebugTx.registerSynchronization(179)
| Synchronization registration on
org.apache.openjpa.kernel.AbstractBrokerFactory$RemoveTransactionSync
29610  ode-dao  INFO   [http-8080-Processor25] openjpa.MetaData - Found
13
classes with metadata in 0 milliseconds.
29834  ode-dao  TRACE  [http-8080-Processor25] openjpa.MetaData -
Loading metadata for "class
org.apache.ode.dao.jpa.MessageExchangeDAOImpl" under mode
"[META][QUERY]".
..........
..........
30386  ode-dao  TRACE  [http-8080-Processor25] openjpa.jdbc.SQL - <t
9601173, conn 16542562> executing prepstmnt 6493766 SELECT t0.ID,
t0.VERSION, t0.GUID, t0.NUMBER_OF_INSTANCES, t0.PROCESS_ID,
t0.PROCESS_TYPE FROM ODE_PROCESS t0 WHERE (t0.PROCESS_ID = ?)
[params=(String) { http://ode/bpel/unit-test}HelloWorld2-1]
30387  ode-dao  TRACE  [http-8080-Processor25] openjpa.jdbc.SQL - <t
9601173, conn 16542562> [0 ms] spent
30388  ode-dao  TRACE  [http-8080-Processor25] openjpa.jdbc.JDBC - <t
9601173, conn 16542562> [0 ms] close detached true WARN -
BPELDAOConnectionFactoryImpl$DebugTxMgr.getTransaction(130) | JPA get
transaction ERROR - BpelServerImpl.bounceProcessDAO(334) | DbError
<2|false|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.EntityExistsException: Attempt to persist
detached object "org.apache.ode.dao.jpa.ProcessDAOImpl@c195e3".
FailedObject: org.apache.ode.dao.jpa.ProcessDAOImpl@c195e3
    at
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2346)
    at
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2204)
    at org.apache.openjpa.kernel.DelegatingBroker.persist(
DelegatingBroker.java:991)
    at org.apache.openjpa.persistence.EntityManagerImpl.persist(
EntityManagerImpl.java:525)
    at org.apache.ode.dao.jpa.BPELDAOConnectionImpl.createProcess(
BPELDAOConnectionImpl.java:78)

Thanks!
Matthieu
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Mime
View raw message