-->
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.  [ 5 posts ] 
Author Message
 Post subject: Cannot use identity column and TABLE_PER_CLASS
PostPosted: Mon Nov 21, 2005 3:41 pm 
Newbie

Joined: Mon Nov 21, 2005 3:38 pm
Posts: 5
I am using annotations to map 3 simple classes (all public)

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
class Property
@Override
@Id(generate=GeneratorType.IDENTITY) // or AUTO
public Integer getId()

@Entity
class TextProperty extends Property

@Entity
class RelationshipProperty extends Property

At runtime I get the following error

Cannot use identity column key generation with <union-subclass> mapping

I don't understand the purpose for this rule. Each class is going into its own table and the name of the table is known at insertion time based on the concrete type of the bean.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 7:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
the same id has to be shared, identity cannot guaranty that

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 8:50 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
Was having the same problem.

Using GenerationType.TABLE seems to be working. I'll test more and post again if it fails in some way.

EDIT -- I spoke too soon. It seems to just duplicate all the fields into the second table in DDL generation.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 11:19 am 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
A rewording of the question is as follows:

What GeneratedValue strategy should be used on an abstract parent class that is defined as Inheritance strategy InheritanceType.TABLE_PER_CLASS, such that the parent and children each have separate tables with no duplicated columns?


Top
 Profile  
 
 Post subject: Re: Cannot use identity column and TABLE_PER_CLASS
PostPosted: Wed Oct 21, 2009 11:19 am 
Newbie

Joined: Mon Aug 03, 2009 2:18 pm
Posts: 2
Quote:
A rewording of the question is as follows:

What GeneratedValue strategy should be used on an abstract parent class that is defined as Inheritance strategy InheritanceType.TABLE_PER_CLASS, such that the parent and children each have separate tables with no duplicated columns?

Answering that question:
Hibernate Annotations Reference Guide tells us (see bold):
http://docs.jboss.org/hibernate/stable/ ... tml#d0e849
Quote:
2.2.4.1. Table per class

This strategy has many drawbacks (esp. with polymorphic queries and associations) explained in the EJB3 spec, the Hibernate reference documentation, Hibernate in Action, and many other places. Hibernate work around most of them implementing this strategy using SQL UNION queries. It is commonly used for the top level of an inheritance hierarchy:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Flight implements Serializable {

This strategy support one to many associations provided that they are bidirectional. This strategy does not support the IDENTITY generator strategy: the id has to be shared across several tables. Consequently, when using this strategy, you should not use AUTO nor IDENTITY.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.