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.  [ 7 posts ] 
Author Message
 Post subject: Bug on Hibernate 3.5 and 3.5.1 related to Generics.
PostPosted: Fri Apr 09, 2010 6:04 am 
Newbie

Joined: Fri Apr 09, 2010 5:49 am
Posts: 10
I tried migrating my project from hibernate 3.4 to hibernate 3.5, and it seems there are problems with generics.
I post my example entities... similar to the one I have it (that are to complicated).
I get an error in the mapping of the OneToMany associationg.

First entity
Code:
@Entity
public class AlarmManager {
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "ID")
   protected long id;

   public long getId() {
      return id;
   }

   protected void setId(long id) {
      this.id = id;
   }
   
   protected String name;

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
   
   
   @OneToMany(   cascade=CascadeType.ALL,
         mappedBy= "alarmManager",
         fetch=FetchType.LAZY
         )
   private List<AbstractAlarm<? extends AbstractCause>> activeAlarmList = new ArrayList<AbstractAlarm<? extends AbstractCause>>();

   public List<AbstractAlarm<? extends AbstractCause>> getActiveAlarmList() {
      return activeAlarmList;
   }

   public void setActiveAlarmList(List<AbstractAlarm<? extends AbstractCause>> activeAlarmList) {
      this.activeAlarmList = activeAlarmList;
   }
}


Second entity
Code:
@Entity
public abstract class AbstractAlarm<E extends AbstractCause> {
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "ID")
   protected long id;

   public long getId() {
      return id;
   }
   
   @ManyToOne
   protected AlarmManager alarmManager;

   public AlarmManager getAlarmManager() {
      return alarmManager;
   }

   public void setAlarmManager(AlarmManager alarmManager) {
      this.alarmManager = alarmManager;
   }

   protected void setId(long id) {
      this.id = id;
   }
   
   protected String name;

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
}


an then something like
Code:
public abstract class AbstractCause {
// . . .
}



if you run a test with these classes in hibernate 3.4 it works.
With hibernate 3.5 no:

this is the stack trace:

Code:
org.hibernate.annotations.common.AssertionFailure: Fail to process type argument in a generic declaration. Type: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
   at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.getClassFromGenericArgument(AttributeFactory.java:836)
   at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:748)
   at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:723)
   at org.hibernate.ejb.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:518)
   at org.hibernate.ejb.metamodel.AttributeFactory.buildAttribute(AttributeFactory.java:93)
   at org.hibernate.ejb.metamodel.MetadataContext.wrapUp(MetadataContext.java:183)
   at org.hibernate.ejb.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:66)
   at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:83)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
   at it.ge.burland.JPABasicTest.init(JPABasicTest.java:30)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
   at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

java.lang.NullPointerException
   at it.ge.burland.JPABasicTest.sweep(JPABasicTest.java:35)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



and this is the code where the Assertion is thrown:
the class is org.hibernate.ejb.metamodel.AttributeFactory:
the type passed is:
it.ge.burland.AbstractAlarm<? extends it.ge.burland.AbstractCause>
and the code inters the else statement
Code:
      private Class<?> getClassFromGenericArgument(java.lang.reflect.Type type) {
         Class<?> javaType;
         Object unsafeElementType = type;
         if ( unsafeElementType instanceof Class ) {
            javaType = (Class) unsafeElementType;
         }
         else if ( unsafeElementType instanceof TypeVariable ) {
            final java.lang.reflect.Type upperBound = ( ( TypeVariable ) unsafeElementType ).getBounds()[0];
            javaType = getClassFromGenericArgument( upperBound );
         }
                         /*********************************
                         *        IT ENTERS HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!
                         **********************************/
         else {
            throw new AssertionFailure("Fail to process type argument in a generic declaration. Type: "
                  + type.getClass() );
         }
         return javaType;
      }

      public ValueContext getElementValueContext() {
         return elementValueContext;
      }

      public PluralAttribute.CollectionType getAttributeCollectionType() {
         return attributeCollectionType;
      }

      public ValueContext getMapKeyValueContext() {
         return keyValueContext;
      }
   }


Even changing the attribute list from:

private List<AbstractAlarm<? extends AbstractCause>> activeAlarmList
to
private List<AbstractAlarm<?>> activeAlarmList

produces the same error.

Is it an error or an expected behaviour?
If it is a bug should I post it on the JIRA?

thanks Davide


Last edited by dgesino on Tue Apr 20, 2010 10:29 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Possible bug with Hibernate 3.5 and generics
PostPosted: Fri Apr 09, 2010 7:02 pm 
Newbie

Joined: Fri Apr 09, 2010 7:00 pm
Posts: 1
I ran into this same issue and created a JIRA issue and patch for it:

http://opensource.atlassian.com/project ... e/HHH-5098


Top
 Profile  
 
 Post subject: Re: Possible bug with Hibernate 3.5 and generics
PostPosted: Fri Apr 16, 2010 5:56 pm 
Newbie

Joined: Fri Apr 16, 2010 5:52 pm
Posts: 1
I have also same problem migarting from 3.3 to 3.5.1

could not complete schema update
org.hibernate.MappingException: Dialect does not support identity key generation
at org.hibernate.dialect.Dialect.getIdentityColumnString(Dialect.java:620)
at org.hibernate.dialect.Dialect.getIdentityColumnString(Dialect.java:610)
at org.hibernate.mapping.Table.sqlCreateString(Table.java:414)
at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:1038)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:187)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:384)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.scotia.thor.persistence.TestEAV1.testLoadDocumentWithIdentifiers(TestEAV1.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Checking 0 named HQL queries
Checking 0 named SQL queries
org.hibernate.annotations.common.AssertionFailure: Fail to process type argument in a generic declaration. Type: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.getClassFromGenericArgument(AttributeFactory.java:836)
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:748)
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:723)
at org.hibernate.ejb.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:518)
at org.hibernate.ejb.metamodel.AttributeFactory.buildAttribute(AttributeFactory.java:93)
at org.hibernate.ejb.metamodel.MetadataContext.wrapUp(MetadataContext.java:183)
at org.hibernate.ejb.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:66)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:83)an assertion failure occured (this may indicate a bug in Hibernate)
org.hibernate.annotations.common.AssertionFailure: Fail to process type argument in a generic declaration. Type: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.getClassFromGenericArgument(AttributeFactory.java:836)
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:748)
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:723)
at org.hibernate.ejb.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:518)
at org.hibernate.ejb.metamodel.AttributeFactory.buildAttribute(AttributeFactory.java:93)
at org.hibernate.ejb.metamodel.MetadataContext.wrapUp(MetadataContext.java:183)
at org.hibernate.ejb.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:66)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:83)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.scotia.thor.persistence.TestEAV1.testLoadDocumentWithIdentifiers(TestEAV1.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.scotia.thor.persistence.TestEAV1.testLoadDocumentWithIdentifiers(TestEAV1.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Top
 Profile  
 
 Post subject: Re: Possible bug with Hibernate 3.5 and generics
PostPosted: Tue Apr 20, 2010 10:27 am 
Newbie

Joined: Fri Apr 09, 2010 5:49 am
Posts: 10
yes, it still gives the same error also to me.


Top
 Profile  
 
 Post subject: Re: Bug on Hibernate 3.5 and 3.5.1 related to Generics.
PostPosted: Wed Jun 23, 2010 11:10 pm 
Newbie

Joined: Sat Dec 05, 2009 1:34 am
Posts: 12
Short of applying the patch and compiling my own version of Hibernate, is there any way around this issue?


Top
 Profile  
 
 Post subject: Re: Bug on Hibernate 3.5 and 3.5.1 related to Generics.
PostPosted: Thu Jun 24, 2010 4:26 am 
Newbie

Joined: Fri Apr 09, 2010 5:49 am
Posts: 10
It has been solved in Hibernate 3.5.3. Give it a try.


Top
 Profile  
 
 Post subject: Re: Bug on Hibernate 3.5 and 3.5.1 related to Generics.
PostPosted: Sat Jul 03, 2010 12:15 am 
Newbie

Joined: Sat Dec 05, 2009 1:34 am
Posts: 12
I gave 3.5.3 a try, and it works great.


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