How to persist a class which extends List<>? [message #1027145] |
Tue, 26 March 2013 12:00  |
Eclipse User |
|
|
|
What annotations are necessary to persist a class which extends List<>?
For example:
@Entity
public class Walk extends ArrayList<Step> implements Serializable { ... }
with a straight entity class Step:
@Entity
public class Step implements Serializable { ... }
Both have simple auto-generated id fields and the appropriate equals() and hashCode() implementations.
I would like the following code to persist the walk including the inserted steps. The entity manager em is created from the factory.
Walk walk = new Walk();
walk.add(new Step());
walk.add(new Step());
walk.add(new Step());
em.getTransaction().begin();
em.persist(walk);
em.getTransaction().commit();
This persists the Walk object in a table which only has an ID-column. No Steps are persisted, nor any relationships. I would expect to need a @OneToMany annotation somewhere, to cascade the persist operation to the Step objects. But where?
Or am I trying to do something that is not possible?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.25140 seconds