-->
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: SecondaryTable and AttributeOverride
PostPosted: Thu May 03, 2007 10:17 am 
Newbie

Joined: Tue Jun 13, 2006 9:03 am
Posts: 18
I'm mixing inheritance strategies but am not sure how to do this with annotations. I have a base abstract entity class that contains an id (the PK). All concrete entities extend from this. For each implementation class, I use the AttributeOverride annotation to override the id name for the table. Now since I'm mixing inheritance strategies--using table-per-class-hierarchy with a join table--and hence I'll need to use the SecondaryTable annotation to join at the pk columns. My question is, how do I specify the pkJoinColumns attribute to use the AttributeOverride of the id? An example of this is shown below:


Code:
@MappedSuperclass
public abstract class AbstractHibernateEntity implements Serializable {
   protected Long id;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }
}


@Entity
@Table(name = "Item")
@AttributeOverride(
   name = "id",
   column = @Column(name = "item_id")
)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
   name = "item_type",
   discriminatorType = DiscriminatorType.STRING
)
public abstract class AbstractItem extends AbstractHibernateEntity {
   protected String name;
   protected BigDecimal value;

   public abstract String shippingLabel();
}

@Entity
@DiscriminatorValue("Returned_Item")
@AttributeOverride(
   name = "id",
   column = @Column(name = "returned_item_id")
)
@SecondaryTable(
   name = "Returned_Item"
   pkJoinColumns = @PrimaryKeyJoinColumn(name = "returned_item_id")
)
public abstract class AbstractReturnedItem extends AbstractItem {

}

@Entity
@DiscriminatorColumn("Damaged_Item")
public class DamagedItem extends AbstractReturnedItem {
  ....
}



The above annotations do not work. I'm thinking its because the SecondaryTable annotation is incorrect for the AbstractReturnedItem class. Also, now that I'm looking at the bigger picture, the AbstractReturnedItem should just be another @MappedSuperclass. Not sure what's right anymore. Any help would be appreciated.

-nefi


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.