-->
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: Discriminator, SecondaryTable and SINGLE_TABLE
PostPosted: Thu Dec 13, 2007 7:08 pm 
Newbie

Joined: Thu Dec 13, 2007 9:48 am
Posts: 3
Hi,

Since discriminators are ignored for the JOINED strategy, I'm trying to simulator the behaviour with a SINGLE_TABLE strategy and a SecondaryTable for the subclass, as suggested here: http://opensource.atlassian.com/projects/hibernate/browse/ANN-562

The schema being generated is not as expected - all columns end up in the root table (FORECAST) and USERFORECAST only has an ID column. I end up with non-nullable columns from the subclass in the same table as the root class(which is concrete). Any ideas what I'm doing wrong here or if I'm missing something?

I'm using Hibernate Annotations 3.3.0.GA with Hibernate 3.2.4.sp1.
Code:
@Entity
@Table(name = "FORECAST")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="DISCR",  discriminatorType=DiscriminatorType.CHAR)
@DiscriminatorValue("F")
public class Forecast {
   @Id @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="ID")
   private long id;
   
   @Column(name = "FORDATE", nullable = false)
   private Calendar date;

   @Column(name = "TEMPF")
   private int temperature;

   @Column(name = "OVERVIEW", length = 300)
   private String overview;
}

@Entity
@SecondaryTable(name="USER_FORECAST")
@DiscriminatorValue("U")
public class UserForecast extends Forecast {

   public static enum CloudType {Cirrus, Cumulus, Status};
   
   @Column(name="USERNAME", length=8, nullable=false)
   private String user = null;
   
   @Column(name="CLOUD_TYPE")   
   @Enumerated(javax.persistence.EnumType.STRING)
   private CloudType cloudType = null;
}


Thanks,
Eoin


Top
 Profile  
 
 Post subject: Solution
PostPosted: Fri Dec 14, 2007 4:08 am 
Newbie

Joined: Thu Dec 13, 2007 9:48 am
Posts: 3
The problem was clear after a night's sleep. I just neglected to put the table="SEC_TABLE_NAME" into the @Column definition for the subclass.

Code:
   @Column(name="USERNAME", table="USER_FORECAST", length=8, nullable=false)
   private String user = null;
   
   @Column(name="CLOUD_TYPE", table="USER_FORECAST")   
   @Enumerated(javax.persistence.EnumType.STRING)
   private CloudType cloudType = null;


-Eoin


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.