I ran into a peculiarity when trying to use subclasses of a parameterized class, the mapper seems to interpret the subclass as typed with the same type parameter.
I'm use the following structure (class names are changed for clarity):
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ParentClass<U> {
private U value;
public void setValue(U value) {
this.value = value;
}
public U getValue() {
return value;
}
Code:
@Entity
public class IntegerSubClass extends ParentClass<Integer>{
}
Code:
public class StringSubClass extends ParentClass<String>{
}
The subclasses don't do a lot, but it's enough to get a generated table for them in the database. The main issue is that both generated tables have
a column called value, and both have the type used by the IntegerSubClass. If I'd change Integer to String both are String, whatever type parameter StringSubClass
specifies. What could cause this behavior and is this behavior of hibernate correct? If so, what could I do to get the right data type for the column?