import org.jboss.logging.Logger;
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.taxeditor.remoting.CdmEagerLoadingException;
-import eu.etaxonomy.taxeditor.remoting.cache.ICachedCommonService;
-import eu.etaxonomy.taxeditor.remoting.cache.CachedCommonServiceImpl.CollectionField;
+import eu.etaxonomy.taxeditor.remoting.cache.ProxyUtils;
+import eu.etaxonomy.taxeditor.service.ICachedCommonService;
/**
* Base class implementing {@link org.hibernate.collection.spi.PersistentCollection}
if ( isTempSession ) {
// TODO: On the next major release, add an
// 'isJTA' or 'getTransactionFactory' method to Session.
- isJTA = session.getTransactionCoordinator()
+ /*isJTA = session.getTransactionCoordinator()
.getTransactionContext().getTransactionEnvironment()
.getTransactionFactory()
- .compatibleWithJtaSynchronization();
-
+ .compatibleWithJtaSynchronization();*/
+ isJTA = session.getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta();
if ( !isJTA ) {
// Explicitly handle the transactions only if we're not in
// a JTA environment. A lazy loading temporary session can
* @throws LazyInitializationException if we cannot initialize
*/
protected final void initialize(final boolean writing) {
- // In remoting we are sure that session is null
- // both when using property paths and switching off conversations
- if(session == null && remoting) {
- remoteInitialize();
- }
-
- if ( initialized ) {
- return;
- }
-
-
- withTemporarySessionIfNeeded(
- new LazyInitializationWork<Object>() {
- @Override
- public Object doWork() {
- session.initializeCollection( AbstractPersistentCollection.this, writing );
- return null;
- }
- }
- );
+ if ( initialized ) {
+ return;
+ }
+
+ // In remoting we are sure that session is null
+ // both when using property paths and switching off conversations
+ if(session == null && remoting) {
+ remoteInitialize();
+ } else {
+ withTemporarySessionIfNeeded(
+ new LazyInitializationWork<Object>() {
+ @Override
+ public Object doWork() {
+ session.initializeCollection( AbstractPersistentCollection.this, writing );
+ return null;
+ }
+ }
+ );
+ }
}
private void throwLazyInitializationExceptionIfNotConnected() {
try {
String role = getRole();
String fieldName = role.substring(role.lastIndexOf(".") + 1);
- log.info("--> Remote Lazy Initializing Collection " + getRole() + " , key : " + getKey() + " , field : " + fieldName);
+ log.info("--> Remote Lazy Initializing Collection " + getRole() + " , owner : " + getOwner().getClass() + "/" + getKey() + " , field : " + fieldName);
Object owner = getOwner();
-
+ CdmBase cdmBase;
+ if(owner instanceof CdmBase) {
+ cdmBase = (CdmBase)owner;
+ } else {
+ throw new HibernateException("Owner of persistent collection is not a cdm entity");
+ }
if(configuration == null) {
throw new HibernateException("CdmApplicationRemoteConfiguration not initialized (null)");
}
throw new HibernateException("commonService not initialized (null)");
}
- PersistentCollection col = cachedCommonService.initializeCollection(this);
+ //Object obj = ProxyUtils.deproxy(cachedCommonService.initializeCollection(this));
+ Object obj = ProxyUtils.deproxy(cachedCommonService.initializeCollection(cdmBase.getUuid(), fieldName));
+ if(ProxyUtils.isProxy(obj)) {
+ throw new HibernateException("Persistent Collection initialized but is still a proxy");
+ }
afterInitialize();
Class<?> clazz = getClass();
if (clazz != null) {
- CollectionField cf = cachedCommonService.getCollectionField(col);
- cachedCommonService.updatePersistentCollection(cf);
- Field field = clazz.getDeclaredField(cf.getType().toString());
+ //CollectionField cf = cachedCommonService.getCollectionField(col);
+ //cachedCommonService.updatePersistentCollection(cf);
+ Object collectionType = ProxyUtils.getCollectionType(obj);
+ Field field = clazz.getDeclaredField(collectionType.toString());
field.setAccessible(true);
- field.set(this, cf.getCollection());
+ field.set(this, obj);
+ ProxyUtils.setRoleValueInOwner(owner, role, obj);
+
}
} catch (Exception ex) {
throw new CdmEagerLoadingException(ex);