Hello
How can I store a List of abstract objects? I have a class that has a List of abstract objects and I'm using the single table strategy to store objects of this list... hmm I think its better to write an example...
I made this way:
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="thingsType")
public [b]abstract [/b]class Thing implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name="oid", nullable=false, insertable=true, updatable=true, length=8)
private Long oid;
...
}
@Entity
@DiscriminatorValue(name="cat")
public class Cat extends Thing{ .... }
@Entity
@DiscriminatorValue(name="human")
public class Human extends Thing{ .... }
@Entity
public class Box implements Serializable {
@OneToMany(fetch=FetchType.EAGER)
@IndexColumn(name="idx")
List<Thing> things;
}
Well I want to record an instance of a box so when I do
Code:
boxDAO.persist(box);
it records all "things" but the values in the thingType column are "Thing", that is, the discriminator value is wrong. I think that happens because hibernate does not verify the type when storing the objects of the list. If I had a thingDAO and store a single cat instance it would work.
How can I successfully store this box object?