-->
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: Mixing Table per subclass and table per class hierarchy
PostPosted: Wed May 25, 2011 6:06 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I'm trying to mix table per subclass and table per class hierarchy (using annotations) and I'm failing. I'm wondering if there is a solution
I'm trying to do the following

Code:
public class A{}
public class B extends class A{}
public class BB extends class B{}


I want A to have its own table, B to have a secondary table and BB to be in the same table as B.

I've tried the following
Code:
@Table(name="A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "A")
public class A{}

@DiscriminatorValue("B")
@SecondaryTable(name="B",   pkJoinColumns =
   {
      @PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
   }
)
public class B extends class A{
@Column(table="JobOffer")
public String getTitle(){}
}

@DiscriminatorValue("BB")
public class BB extends class B{}
@Column
public int getValue(){}


This leads to all fields in BB to be stored in table A in stead of table B.

If I try
Code:
@Table(name="A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "A")
public class A{}

@DiscriminatorValue("B")
@SecondaryTable(name="B",   pkJoinColumns =
   {
      @PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
   }
)
public class B extends class A{
@Column(table="JobOffer")
public String getTitle(){}
}

@DiscriminatorValue("BB")
@SecondaryTable(name="B",   pkJoinColumns =
   {
      @PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
   }
)
public class BB extends class B{}
@Column(table="B")
public int getValue(){}


I will get a duplicate aID mySQL error trying to insert a new BB twice, once as a B and once as a BB.

If I try
Code:
@Table(name="A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "A")
public class A{}

@DiscriminatorValue("B")
@SecondaryTable(name="B",   pkJoinColumns =
   {
      @PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
   }
)
public class B extends class A{
@Column(table="B")
public String getTitle(){}
}

@DiscriminatorValue("BB")
public class BB extends class B{}
@Column(table="B")
public int getValue(){}


I will get a Hibernate error during startup.

Any ideas on how to get this working?

Kind regards,

Marc


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.