Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.2
DB : mysql 4
I am trying to map a single one to many relation :
Code:
@Entity()
@Table(name = "Image")
@Inheritance( strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "Type", discriminatorType = DiscriminatorType.STRING)
public abstract class AbstractImage
Code:
@Entity
@DiscriminatorValue("Cover")
public class ImageCover extends AbstractImage
Code:
@Entity
@DiscriminatorValue("Preview")
public class ImagePreview extends AbstractImage
And in the one-side , Item may have one-to-many CoverImages and PreviewImages :
Code:
//ImageCover
@OneToMany(fetch=FetchType.LAZY , mappedBy="item" )
@Cascade(value = {CascadeType.SAVE_UPDATE , CascadeType.DELETE_ORPHAN} )
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<ImageCover> coverImages = new HashSet<ImageCover>();
// ImagePreview
@OneToMany(fetch=FetchType.LAZY , mappedBy="item" )
@Cascade(value = {CascadeType.SAVE_UPDATE , CascadeType.DELETE_ORPHAN} )
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<ImagePreview> previewImages = new HashSet<ImagePreview>();
When saving , it works OK. The DiscriminatorValue is correctly written to DiscriminatorColumn
But when loading objects : it seems hibernate cannot tell from the inheritancing class , I didn't see Type='Cover' or Type='Preview' in the generated SQL :
Code:
Hibernate: select coverimage0_.ItemID as ItemID1_, coverimage0_.ID as ID1_, coverimage0_.ID as ID6_0_, coverimage0_.ItemID as ItemID6_0_, coverimage0_.location as location6_0_, coverimage0_.data as data6_0_, coverimage0_.size as size6_0_ from Image coverimage0_ where coverimage0_.ItemID=?
What may be wrong ?