Hibernate version: 3.2.2-ga
Hibernate Annotations version: 3.2.1-ga
Hi, I'm trying to setup an inheritance hierarchy on a property using Java generics, but I am getting the following exception:
Quote:
org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined
So, either the syntax of what I'm trying to do is incorrect, or just not supported by Hibernate. Any help solving the simple example described below would be greatly appreciated.
The area I'm working in is the GIS domain, where we have entity objects that represent POINT, LINE, AREA, etc. geometric features. Each of these objects also has attributes attached to them, thus there is a POINT_ATTRIBUTE, LINE_ATTRIBUTE, AREA_ATTRIBUTE table. The DDL for the attribute tables is identical, thus the Entity objects PointAttribute, LineAttribute, AreaAttribute has all the same methods essentially.
So, I need to abstract out a generic interface. For example on the Point entity object I want to do this:
Code:
@Entity
@Table(name = "POINT")
public final class Point {
private Set<PointAttribute> pointAttributes;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "point")
@Target(PointAttribute.class)
public final Set<? extends Attribute> getAttributes() {
return pointAttributes;
}
}
I use the Target annotation to tell hibernate what the concrete type is there.
Then I have the class PointAttribute:
Code:
@Entity
@Table(name = "POINT_ATTRIBUTE")
public class PointAttribute implements Serializable, Attribute {
// getters/setters
}
...and finally I have the Attribute interface:
Code:
public interface Attribute extends Serializable {
// same getters/setters
}
The idea is that I can do this for each Point, Line, Area class, so the common return type on each is Attribute since the method signatures are the same for all *Attribute domain objects.
Unfotunately, if I try this, I get the exception noted above. What am I doing wrong?
Thanks in advance,
Davis