-->
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.  [ 6 posts ] 
Author Message
 Post subject: native id generation with union-subclass
PostPosted: Wed Apr 27, 2005 10:32 pm 
Newbie

Joined: Wed Apr 27, 2005 10:22 pm
Posts: 8
I'm trying to use the "Table per concrete class" inheritance functionality. The example in the hibernate docs (http://www.hibernate.org/hib_docs/v3/re ... strategies) is this:
<class name="Payment">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
<property name="amount" column="AMOUNT"/>
...
<union-subclass name="CreditCardPayment" table="CREDIT_PAYMENT">
<property name="creditCardType" column="CCTYPE"/>
...
</union-subclass>
<union-subclass name="CashPayment" table="CASH_PAYMENT">
...
</union-subclass>
<union-subclass name="ChequePayment" table="CHEQUE_PAYMENT">
...
</union-subclass>
</class>

And yet, when I look at UnionSubclassEntityPersister, line 61, I see this:
if ( getIdentifierGenerator() instanceof IdentityGenerator ) {
throw new MappingException(
"Cannot use identity column key generation with <union-subclass> mapping for: " + getEntityName());
}

I'm guessing the docs are wrong since the code prohibits this quite clearly. Anybody know why this is prohibited?

Thanks,
Max


Hibernate version:
3.0.2

Mapping documents:
<class name="Base">
<id name="val" column="val" type="integer">
<generator class="identity"/>
</id>
<union-subclass name="Child1" table="Child1">
<property name="val1" column="val1" not-null="false"/>
</union-subclass>
<union-subclass name="Child2" table="Child2">
<property name="val2" column="val2" not-null="false"/>
</union-subclass>
</class>

Full stack trace of any exception that occurs:
Caused by: org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: Child1
at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:61)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1054)

Name and version of the database you are using:MySql 4


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 6:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'll fix the doc.
Using identity generator, you cannot share the same id seed between different tables. And the id has to be unique whithin the hierarchy.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 3:42 am 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
I am using Hibernate 3.2
The document still gives the same example (probably it hasnt been updated).

Now I am having the exact same scenario, where I have an interface with 2 concrete implementations and therefore I am getting the same error
org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: Child1

Can anybody please share, how to solve this issue? How do I specify the surrogate key? Any reference to documentation/example if available will be highly appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 8:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no the example show a sequence now.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 8:17 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Thanks. I will need to do a little more reading here, since sequence doesnt work for MySql.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 8:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hilo will work for you then

_________________
Emmanuel


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