-->
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: issue with inheritance
PostPosted: Sat Jul 16, 2005 4:52 am 
Newbie

Joined: Thu Jul 14, 2005 3:24 pm
Posts: 3
Hello,

I've noticed a minor issue with inheritance - if ID is declared both in the superclass and the subclass the ClassCastException is thrown. I'm not really sure if it's a bug, all i could find about IDs in the spec was:

"When an entity is defined as a subclass of another entity, the primary keys of the entities must be of the same type."

but does that mean the ID in the subclass has to be inherited or may it be declared? Would it even make sense to declare it twice?

Anyway, i've experimented a bit and same thing happens with all three types of inheritance. Here is the stack trace:

javax.persistence.PersistenceException: java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:100)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:42)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:29)
<snip>
Caused by: java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1274)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:843)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:562)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:174)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:825)
at org.hibernate.ejb.HibernatePersistence.handleCallbacks(HibernatePersistence.java:189)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:180)
at org.hibernate.ejb.HibernatePersistence.createFactory(HibernatePersistence.java:77)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:93)
... 19 more

and here is the code line that causes the problem (org.hibernate.cfg.AnnotationBinder)

1274: RootClass rootClass = (RootClass) propertyHolder.getPersistentClass();

the propertryHolder holds instance of org.hibernate.cfg.ClassPropertyHolder.

I'm not much into the guts of Hibernate, but i tryed to get deeper. I noticed the usage of EntityBinder class and the fact that if i set it's ignoreIdAnnotations property to true, more or less before this call takes place (AnnotationBinder):

562: processElementAnnotations(propertyHolder,
563: subclassAndSingleTableStrategy ? Nullability.FORCED_NULL : Nullability.NO_CONSTRAINT,
564: propertyAnnotatedElement.element,
565: propertyAnnotatedElement.inferredData, classGenerators, classGeneratorTables, entityBinder, false, mappings);

(of course when the id is being processed), Hibernate will treat it as an ordinary property and create a nullable column in the database.

As i've said i'm not really sure what should happen in such situation, but even if it's not allowed to declare the id in subclasses, the ClassCastException is rather ugly way of saying this :)

Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this is not allowed.
Post a JIRA improvement for that please.

_________________
Emmanuel


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.