-->
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.  [ 3 posts ] 
Author Message
 Post subject: Multi-level Generics causing Hibernate assertion failure
PostPosted: Thu Mar 30, 2006 6:53 pm 
Newbie

Joined: Thu Mar 30, 2006 6:25 pm
Posts: 2
Hibernate version: 3.1.2
Mapping documents: Annotations 3.1b8
Code between sessionFactory.openSession() and session.close(): We don't get that far.
Full stack trace of any exception that occurs: Story first...

Suppose you define a base class for all Hibernate-persisted classes:

/**
* @param <I> The type (class) to be used for the ID field.
* @param <V> The type (class) to be used for the Version field.
*/
@MappedSuperclass
public abstract class HibernateBase<I, V> implements Serializable {
protected I id = null;
protected V version = null;
<<accessors omitted>>
}

Now suppose you further extend that with another base class for Hibernate-persisted classes that use typed Property objects:

/***
* @param <I> The type (class) to be used for the ID field.
* @param <V> The type (class) to be used for the Version field.
* @param <P> The type (class) to be used for the Properties, which must extend PropertyBase.
*/
@MappedSuperclass
public abstract class PropertiesBase<I, V, P extends PropertyBase> extends HibernateBase<I, V> {
<<omitted...>>
}

Next in your inheritance tree you provide a class that defines all three generics listed so far:

@MappedSuperclass
public abstract class TaskBase extends PropertiesBase<Integer, Integer, TaskProperty> {
<<omitted...>>
}

And finally, a domain-specific implementation class to actually be used:

@Entity
@Table(name = "te_task")
public class CMEJTask extends TaskBase {
<<omitted...>>
}

When you try to start this code, you will get the error listed below. Note that this worked just fine when the middle class, PropertiesBase, defined the generic classes. It wasn't until I pushed them down one level further, to the TaskBase, that I received the Hibernate assertion failure. Java lets me "carry" my generics through multiple levels of inheritance, so I'm wondering if this might not be a Hibernate bug.

781 [main] DEBUG org.hibernate.cfg.annotations.EntityBinder - Import with entity name=CMEJTask
821 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.infor.dist.te.sxe.model.CMEJTask on table te_task
821 [main] DEBUG org.hibernate.cfg.AnnotationBinder - Processing com.infor.dist.te.sxe.model.CMEJTask per property annotation
841 [main] ERROR org.hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: Unable to extract type of property id: I
at org.hibernate.cfg.PropertyInferredData.extractType(PropertyInferredData.java:236)
at org.hibernate.cfg.PropertyInferredData.execute(PropertyInferredData.java:124)
at org.hibernate.cfg.PropertyInferredData.skip(PropertyInferredData.java:60)
at org.hibernate.cfg.AnnotationBinder.addAnnotatedElement(AnnotationBinder.java:900)
at org.hibernate.cfg.AnnotationBinder.addElementsOfAClass(AnnotationBinder.java:868)
at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:717)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:547)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:276)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:210)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 8:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try beta9
Paolo and Davide have coimpletly rewritten this area

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Not the silver bullet
PostPosted: Fri Mar 31, 2006 11:41 am 
Newbie

Joined: Thu Mar 30, 2006 6:25 pm
Posts: 2
Switching to Hibernate 3.1.3 and Annotations beta 9 did change the error I get:

841 [main] DEBUG org.hibernate.cfg.annotations.EntityBinder - Import with entity name=CMEJTask
901 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.infor.dist.te.sxe.model.CMEJTask on table te_task
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDAO' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'userDAOTarget' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDAOTarget' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'teSessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teSessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Property id has an unbound type and no explicit target entity.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDAOTarget' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'teSessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teSessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Property id has an unbound type and no explicit target entity.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teSessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Property id has an unbound type and no explicit target entity.
java.lang.IllegalStateException: Property id has an unbound type and no explicit target entity.
at org.hibernate.cfg.AnnotationBinder.addElementsOfAClass(AnnotationBinder.java:873)
at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:727)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:561)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:295)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:216)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168)


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