HHH-3744: applying the patch.
Thank you to Ben Clark! git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15835 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
e6c9326438
commit
1a1118c0bb
|
@ -79,7 +79,9 @@ public class SubclassPropertyMapper implements ExtendedPropertyMapper {
|
||||||
if (parentCollectionChanges == null) {
|
if (parentCollectionChanges == null) {
|
||||||
return mainCollectionChanges;
|
return mainCollectionChanges;
|
||||||
} else {
|
} else {
|
||||||
|
if(mainCollectionChanges != null) {
|
||||||
parentCollectionChanges.addAll(mainCollectionChanges);
|
parentCollectionChanges.addAll(mainCollectionChanges);
|
||||||
|
}
|
||||||
return parentCollectionChanges;
|
return parentCollectionChanges;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.hibernate.envers.tools.reflection.ReflectionTools;
|
||||||
|
|
||||||
import org.hibernate.property.Getter;
|
import org.hibernate.property.Getter;
|
||||||
import org.hibernate.property.Setter;
|
import org.hibernate.property.Setter;
|
||||||
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -77,9 +78,14 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data instanceof HibernateProxy) {
|
||||||
|
HibernateProxy hibernateProxy = (HibernateProxy) data;
|
||||||
|
return hibernateProxy.getHibernateLazyInitializer().getIdentifier();
|
||||||
|
} else {
|
||||||
Getter getter = ReflectionTools.getGetter(data.getClass(), propertyData);
|
Getter getter = ReflectionTools.getGetter(data.getClass(), propertyData);
|
||||||
return getter.get(data);
|
return getter.get(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void mapToMapFromId(Map<String, Object> data, Object obj) {
|
public void mapToMapFromId(Map<String, Object> data, Object obj) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
@ -90,11 +96,16 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
||||||
public void mapToMapFromEntity(Map<String, Object> data, Object obj) {
|
public void mapToMapFromEntity(Map<String, Object> data, Object obj) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
data.put(propertyData.getName(), null);
|
data.put(propertyData.getName(), null);
|
||||||
|
} else {
|
||||||
|
if(obj instanceof HibernateProxy) {
|
||||||
|
HibernateProxy hibernateProxy = (HibernateProxy)obj;
|
||||||
|
data.put(propertyData.getName(), hibernateProxy.getHibernateLazyInitializer().getIdentifier());
|
||||||
} else {
|
} else {
|
||||||
Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData);
|
Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData);
|
||||||
data.put(propertyData.getName(), getter.get(obj));
|
data.put(propertyData.getName(), getter.get(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void mapToEntityFromEntity(Object objTo, Object objFrom) {
|
public void mapToEntityFromEntity(Object objTo, Object objFrom) {
|
||||||
if (objTo == null || objFrom == null) {
|
if (objTo == null || objFrom == null) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ import org.hibernate.event.PreCollectionRemoveEventListener;
|
||||||
import org.hibernate.event.PreCollectionUpdateEvent;
|
import org.hibernate.event.PreCollectionUpdateEvent;
|
||||||
import org.hibernate.event.PreCollectionUpdateEventListener;
|
import org.hibernate.event.PreCollectionUpdateEventListener;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -64,6 +65,8 @@ import org.hibernate.persister.entity.EntityPersister;
|
||||||
public class AuditEventListener implements PostInsertEventListener, PostUpdateEventListener,
|
public class AuditEventListener implements PostInsertEventListener, PostUpdateEventListener,
|
||||||
PostDeleteEventListener, PreCollectionUpdateEventListener, PreCollectionRemoveEventListener,
|
PostDeleteEventListener, PreCollectionUpdateEventListener, PreCollectionRemoveEventListener,
|
||||||
PostCollectionRecreateEventListener, Initializable {
|
PostCollectionRecreateEventListener, Initializable {
|
||||||
|
private static final long serialVersionUID = -2499904286323112715L;
|
||||||
|
|
||||||
private AuditConfiguration verCfg;
|
private AuditConfiguration verCfg;
|
||||||
|
|
||||||
private void generateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, EntityPersister entityPersister,
|
private void generateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, EntityPersister entityPersister,
|
||||||
|
@ -93,7 +96,14 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
|
||||||
if (newValue != null) {
|
if (newValue != null) {
|
||||||
// relDesc.getToEntityName() doesn't always return the entity name of the value - in case
|
// relDesc.getToEntityName() doesn't always return the entity name of the value - in case
|
||||||
// of subclasses, this will be root class, no the actual class. So it can't be used here.
|
// of subclasses, this will be root class, no the actual class. So it can't be used here.
|
||||||
String toEntityName = session.guessEntityName(newValue);
|
String toEntityName;
|
||||||
|
if(newValue instanceof HibernateProxy) {
|
||||||
|
HibernateProxy hibernateProxy = (HibernateProxy) newValue;
|
||||||
|
toEntityName = session.bestGuessEntityName(newValue);
|
||||||
|
newValue = hibernateProxy.getHibernateLazyInitializer().getImplementation();
|
||||||
|
} else {
|
||||||
|
toEntityName = session.guessEntityName(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
|
IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
|
||||||
|
|
||||||
|
@ -102,7 +112,14 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldValue != null) {
|
if (oldValue != null) {
|
||||||
String toEntityName = session.guessEntityName(oldValue);
|
String toEntityName;
|
||||||
|
if(oldValue instanceof HibernateProxy) {
|
||||||
|
HibernateProxy hibernateProxy = (HibernateProxy) oldValue;
|
||||||
|
toEntityName = session.bestGuessEntityName(oldValue);
|
||||||
|
oldValue = hibernateProxy.getHibernateLazyInitializer().getImplementation();
|
||||||
|
} else {
|
||||||
|
toEntityName = session.guessEntityName(oldValue);
|
||||||
|
}
|
||||||
|
|
||||||
IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
|
IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
|
||||||
Serializable snapshot, Serializable id) {
|
Serializable snapshot, Serializable id) {
|
||||||
super(entityName, verCfg, null);
|
super(entityName, verCfg, null);
|
||||||
|
|
||||||
referencingPropertyName = role.substring(entityName.length() + 1);
|
referencingPropertyName = role.substring(role.lastIndexOf(".") + 1);
|
||||||
|
|
||||||
collectionChanges = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
collectionChanges = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
||||||
.mapCollectionChanges(referencingPropertyName, collection, snapshot, id);
|
.mapCollectionChanges(referencingPropertyName, collection, snapshot, id);
|
||||||
|
|
Loading…
Reference in New Issue