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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class Range<t> {
  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:

1

Comments