Hi all,
I'v in trouble to link together two hierarchies at the top level (security). i've successed for most cases but some still fail.
I've a hierarcy of domain entities whose derived from a generic SecuredClass annotated with @MappedSuperclass (so not an entity).
This SecuredClass has a one to many to an abstract entity SecurityClass.
This abstract security class has the backward many to one link to a default SecuredClass (because ManyToOne needs Entity) : ItemClass.
Then for all first childre of SecuredClass we can create a New specific SecurityClass with the correspondant field... Ok I know that's really tricky. I use annotation for that :
Code:
@MappedSuperclass
SecuredClass {
@OneToMany(
mappedBy = "securedObject",
fetch = FetchType.LAZY,
targetEntity = SecurityClass.class)
SecurityClass rights;
}
//This is one secured entity
@Entity
ItemClass extends SecuredClass {
}
//This is another secured entity
@Entity
PropertyClass extends SecuredClass {
}
========security part==========
@Entity //[b]manyToOne needs Entity in SecuredClass[/b]
abstract SecurityClass {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ITEM", nullable = true)
//Note [b]NO FK [/b](schema manually managed)
//Note [b]ItemClass[/b] entity is the default entity
//Note the [b]private[/b]
private ItemClass securedObject = null;
//ACCESSOR
}
@Entity
ItemSecurityClass extends SecurityClass {}
@Entity
PropertySecurityClass extends SecurityClass {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PROPERTY", nullable = true)
//Note [b]NO FK [/b](schema manually managed)
//Note [b]ItemClass[/b] entity is the default entity
//Note the [b]private[/b]
private PropertyClass securedObject;
//ACCESSOR => OVERRIDEN
}
So, I told it... it's tricky. but it works in most cases. Missing ones are :
1] When creating and persiting a PropertySecurityClass the Tuplizer will add the PropertyClass.id to both the PROPERTY and ITEM columns
2] When PropertySecurityClasses have to be retrieved Lazily, Hibernate throw a System exception "setter" saying that he can set the 'securedObject' on a PropertySecurityClass instance.
Those problems occurs because :
1] both the SecurityClass.securedObject and PropertySecurityClass.securedObject are mapped on the same object (PropertyGetter) => the value are added at both places
2] it's the same kind of problem, hibernate wants to set both the SecurityClass.securedObject and PropertySecurityClass.securedObject with the propertyClass instance he has.
So it seems either to be a "bug" in hibernate to not support the private field overrided or this particular tricky schema isn't permitted.
What do think ? Could I reach my goal using my own Tuplizer ?
thanks very much in advance ^^
PS : sorry for the bad english[/b]