Hi all,
I'm trying to implement my object model exclusively using EJB3/Hibernate annotations. I want to define a base class that indicates associations, permissions, etc and have all my domain entities extend it.
It would look something like this:
Code:
Interface ZObject
|
abstract class BaseZObject implements ZObject
|
class SomeZObject extends BaseZObject
Code:
public abstract class BaseZObject implements ZObject {
@Keyword(id=true)
public void setId(Long inid) { // see #1 below
id = inid;
}
@ManyToMany(cascade = {CascadeType.PERSIST})
public Set<ZClassification> getZClassifications() {
return classifications;
}
//...
}
public class ZClassification extends BaseZObject {
@ManyToMany(mappedBy="classifications")
public Set<BaseZObject> getBaseZObjects() { // see #2
return zobjects;
}
// ...
}
public class SomeZObject extends BaseZObject {
@Column (length = 60)
public String getSomfield {
return somedata;
}
// ...
}
(Sorry if the above isn't quite right, I hope you get the idea).
However, I encounter issues..
#1 I can't seem to implement ID details in the base abstract class or interface. I get "no identifier specified" for SomeZObject.
#2 the classifications mapping fails with "Collection of elements must not have mappedBy or association reference an unmapped entity: baseZObjects" - This would evidently be because BaseZObject is not mapped, but I don't want to map my base class, but rather implementations of it.
I've also tried permutations adding the annotations in the interface rather than base class, but nothing has worked.
I'd like to try to implement this quickly for a prototype, or I'll have to go back to "the old ways." Does anyone have any advice? I'm open to commercial remote consulting/mentoring.
Thanks!
David