-->
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.  [ 2 posts ] 
Author Message
 Post subject: @DiscriminatorValue skipped when loading objects
PostPosted: Mon Mar 05, 2007 3:10 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:46 am
Posts: 34
Location: Taiwan
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 ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 3:23 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:46 am
Posts: 34
Location: Taiwan
sorry , I found the problem.
It seems the hibernate problem :
http://jroller.com/page/eyallupu?entry= ... en_mapping


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

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.