i'm trying migrate application uses unsynchronized persistence context jta transaction, hibernate 4.3.7 hibernate 5.0.7, , found couple of issues can't head around. our entity manager injected
@persistencecontext(type = persistencecontexttype.extended, synchronization = synchronizationtype.unsynchronized) private entitymanager entitymanager;
so expect have extended , unsynchronized persistence context. application uses unsynchronized feature avoid flushing changes entities database until want so. normally, want flush changes after save/persist/remove operations , these methods calling entitymanager.jointransaction();
explicitly mark current transaction synchronisation. used work degree in hibernate 4.3.7 stopped in version 5.
for version 5, hiberante guys did quite lot of rewriting, particularly in transaction handling area. understanding, hibernate uses session.autojointransactions flag implement unsynchronized feature. session not flushed (we use default flushmode.auto) unless session joined transaction. previously, flag set new session
sessionbuilder.autojointransactions( gettransactiontype() != persistenceunittransactiontype.jta );
and in hibernate 5 (entitymanagetimpl line 132)
sessionbuilder.autojointransactions( getsynchronizationtype() == synchronizationtype.synchronized );
as use jta managed transactions used work. not. seems decide value autojointransaction
flag based on synchronizationtype right thing do, there 1 small problem. persistencecontexttyoe not propagated entityfactoryimpl methods , therefore entity manager created synchronised. when injecting entitymanager wildlfy calling first method , not second one.
@override public entitymanager createentitymanager(map map) { return internalcreateentitymanager( synchronizationtype.synchronized, map ); } @override public entitymanager createentitymanager(synchronizationtype synchronizationtype, map map) { errorifresourcelocalduetoexplicitsynchronizationtype(); return internalcreateentitymanager( synchronizationtype, map ); }
so questions: how inject instance of entity manager unsynchronized persistence context? why wildfly
ignores type = persistencecontexttype.extended
parameter when injecting entity manager? missing something?
as synchronisation type propagate injected enntiymanager, realised can use entitymanagerfactory create entitymanger. factory has method accepting synchronisation type create unsynchronised context.
@persistenceunit private entitymanagerfactory emf; ... emf.createentitymanager(synchronizationtype.unsynchronized);
also, found issue logged against wildfly 8.1 https://issues.jboss.org/browse/wfly-5006
Comments
Post a Comment