Hello,
I'm new to your issue tracking system and at first I would like to thank you for your years of work on hibernate.
I have JPA-Entities with composite primary keys ( and therefore composite foreign keys ). They consist of (Id : String, ClientId : String) and the Id-Class is not mapped as embedded. {code} /** * Gruppe entity id class. * @see Gruppe */ @SuppressWarnings("all") public class _GruppeId implements CLId {
@Column(name = "ID") private String Id;
@Column(name = "CLIENTID") private String ClientId; public _GruppeId() {} public _GruppeId(String aId, String aClientId) { setId(aId); setClientId(aClientId); } public String getId() { return Id; }
public void setId(String aId) { this.Id = aId; }
public String getClientId() {
return ClientId; }
public void setClientId(String aClientId) { ClientId = aClientId; }
public boolean equals(Object o) { return ((o instanceof _GruppeId) && getId().equals(((_GruppeId)o).getId()) && getClientId().equals(((_GruppeId) o).getClientId())); }
public int hashCode() { return Id.hashCode() + getClientId().hashCode(); }
@Override public String toString() { Class<?> clazz = getClass(); return clazz.getSimpleName() + "@Id=" + getId() + ",ClientId=" + getClientId(); } } {code} {code} /** * Gruppe entity instance implementation. */ @Audited @Entity(name="Gruppe") @IdClass(_GruppeId.class) @FilterDef(name="ClientIdFilter", parameters={ @ParamDef( name="ClientId", type="string" ) } ) @Filter(name="ClientIdFilter", condition="CLIENTID = :ClientId") @Table(name="GRUPPE", indexes = { }) @Proxy(lazy=true, proxyClass=_GruppeProxy.class) @SuppressWarnings("all") public class _GruppeImpl extends CLEntityImpl implements _GruppeProxy {
/** * client to which the entity belongs */ @Column(name = "CLIENTID") private String ClientId;
@Basic @Column(name="NAME") private String ivName;
public _GruppeImpl() {
this(0); createEntityBL(); }
//only another constructor protected _GruppeImpl(int aParam) {
super(aParam);
}
public EntityPK getPK () {
_GruppePKImpl gruppePKImpl = new _GruppePKImpl(); gruppePKImpl.setId(getId()); gruppePKImpl.setClientId(getClientId()); gruppePKImpl.setLock_Version(getLock_Version()); return gruppePKImpl; }
@Override public boolean equals(Object o) { return ((o instanceof Gruppe) && getPK().equals(((Gruppe)o).getPK())); } @Override public int hashCode() {
return getPK().hashCode(); } /** * getter for Client. */ public String getClientId() {
return ClientId; }
/** * setter for Client. */ public void setClientId(String aClientId) {
ClientId = aClientId; } @Override public String getName() { return ivName; } @Override public void setName(String aName) { checkStringForEmptyness(aName); ivName = aName; } {code} When trying to audit a relation to another entity with envers, Hibernate's {code} BasicBinder {code} class fails with a ClassCastException on trying to setting set Id-Class instance to ClientId/Id-values, when trying to persist to the audit table. After spending a few hours of work, I found out, that in class org.hibernate.envers.internal.entities.mapper.id.SingleIdMapper.mapToMapFromEntity(...) {code} SingleIdMapper.mapToMapFromEntity(...) @Override public void mapToMapFromEntity(Map<String, Object> data, Object obj) { if ( obj == null ) { data.put( propertyData.getName(), null ); } else { if ( obj instanceof HibernateProxy ) { final HibernateProxy hibernateProxy = (HibernateProxy) obj; data.put( propertyData.getName(), hibernateProxy.getHibernateLazyInitializer().getIdentifier() ); } else { final Getter getter = ReflectionTools.getGetter( obj.getClass(), propertyData ); data.put( propertyData.getName(), getter.get( obj ) ); } } } {code} When trying properties of the Id-Class are not extracted, when having a proxy. This seems to use be a bug, |
|