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:
Adam Warski 2009-01-30 12:01:00 +00:00
parent e6c9326438
commit 1a1118c0bb
4 changed files with 39 additions and 9 deletions

View File

@ -79,7 +79,9 @@ public class SubclassPropertyMapper implements ExtendedPropertyMapper {
if (parentCollectionChanges == null) {
return mainCollectionChanges;
} else {
parentCollectionChanges.addAll(mainCollectionChanges);
if(mainCollectionChanges != null) {
parentCollectionChanges.addAll(mainCollectionChanges);
}
return parentCollectionChanges;
}
}

View File

@ -33,6 +33,7 @@ import org.hibernate.envers.tools.reflection.ReflectionTools;
import org.hibernate.property.Getter;
import org.hibernate.property.Setter;
import org.hibernate.proxy.HibernateProxy;
/**
* @author Adam Warski (adam at warski dot org)
@ -77,8 +78,13 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
return null;
}
Getter getter = ReflectionTools.getGetter(data.getClass(), propertyData);
return getter.get(data);
if(data instanceof HibernateProxy) {
HibernateProxy hibernateProxy = (HibernateProxy) data;
return hibernateProxy.getHibernateLazyInitializer().getIdentifier();
} else {
Getter getter = ReflectionTools.getGetter(data.getClass(), propertyData);
return getter.get(data);
}
}
public void mapToMapFromId(Map<String, Object> data, Object obj) {
@ -91,8 +97,13 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
if (obj == null) {
data.put(propertyData.getName(), null);
} else {
Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData);
data.put(propertyData.getName(), getter.get(obj));
if(obj instanceof HibernateProxy) {
HibernateProxy hibernateProxy = (HibernateProxy)obj;
data.put(propertyData.getName(), hibernateProxy.getHibernateLazyInitializer().getIdentifier());
} else {
Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData);
data.put(propertyData.getName(), getter.get(obj));
}
}
}

View File

@ -57,6 +57,7 @@ import org.hibernate.event.PreCollectionRemoveEventListener;
import org.hibernate.event.PreCollectionUpdateEvent;
import org.hibernate.event.PreCollectionUpdateEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
/**
* @author Adam Warski (adam at warski dot org)
@ -64,6 +65,8 @@ import org.hibernate.persister.entity.EntityPersister;
public class AuditEventListener implements PostInsertEventListener, PostUpdateEventListener,
PostDeleteEventListener, PreCollectionUpdateEventListener, PreCollectionRemoveEventListener,
PostCollectionRecreateEventListener, Initializable {
private static final long serialVersionUID = -2499904286323112715L;
private AuditConfiguration verCfg;
private void generateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, EntityPersister entityPersister,
@ -93,7 +96,14 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
if (newValue != null) {
// 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.
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();
@ -102,8 +112,15 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
}
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();
Serializable id = (Serializable) idMapper.mapToIdFromEntity(oldValue);

View File

@ -46,7 +46,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
Serializable snapshot, Serializable id) {
super(entityName, verCfg, null);
referencingPropertyName = role.substring(entityName.length() + 1);
referencingPropertyName = role.substring(role.lastIndexOf(".") + 1);
collectionChanges = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
.mapCollectionChanges(referencingPropertyName, collection, snapshot, id);