Hibernate and Generics
Wherever possible I try to apply some principles from Domain Driven Design. So I also use Value Objects – some of them implemented based on Java5 Generics
Example:
public class Range {
private T start;
private T end;
public Range() {
super();
}
public Range(T start, T end) {
super();
this.start = start;
this.end = end;
}
public T getStart() {
return start;
}
public void setStart(T start) {
this.start = start;
}
public T getEnd() {
return end;
}
public void setEnd(T end) {
this.end = end;
}
}
Hibernate is not able to determine the proper type (org.hibernate.MappingException: property mapping has wrong number of columns …) for the properties of the value object unless they are explicitely described in the class mapping.
For a Range with Date as template parameter you would map:
