-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Storing a list of abstract objects
PostPosted: Wed Aug 26, 2009 2:05 pm 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.