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: @Column with table reference for @SecondaryTable in parent
PostPosted: Thu Jul 07, 2011 6:52 am 
Newbie

Joined: Thu Jul 07, 2011 6:34 am
Posts: 1
I have a deep Class Hierarchy with a shallow Table hierarchy. The class hierarchy is (more or less):
Code:
@Entity
@Table(name = "ANCESTOR_TABLE")
@Inheritance(strategy = SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = STRING, length = 3)
public abstract class Ancestor
{
  @Id @Column(name = "ID")
  private Long id;
}

@Entity
@DiscriminatorValue("AAA")
@SecondaryTable(name = "PARENT_TABLE")
public class Parent
  extends Ancestor
{
  @Column(table = "PARENT_TABLE", name = "PARENT_FIELD")
  private String parentField;
}

@Entity
@DiscriminatorValue("BBB")
public class Child
  extends Parent
{
  @Column(table = "PARENT_TABLE", name = "CHILD_FIELD")
  private String childField;
}


With Eclipselink this worked as intended: Parent as well as Child have additional columns in the same secondary table.

When I try this with Hibernate 3.6, the first complaint is that table "PARENT_TABLE" is unknown during the mapping of Child. If I add a @SecondaryTable() to Child this complaint disappears, and selects work as intended. However, updates and inserts now assume an additional table which happens to have the same name as the one from Parent, resulting in 3 insert SQL statements being sent to the DB.

I think there are two issues with this:
1) If the behaviour with two @SecondaryTable annotations is intended, I think Hibernate should complain about the second secondary table having the same name as the first.
2) It appears impossible to refer to a secondary table defined in a parent class.

Switching inheritance strategy halfway would solve my problem as well (start with JOINED, continue one level down with SINGLE_TABLE) but that is not possible I guess...

Any ideas?

Bert Laverman


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.