Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Fri Jun 02, 2017 7:51 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
I am trying to upgrade the Hibernate version of our project from 4.3 to 5.2. I have gone through the steps required for upgrading by going through the following documents

    https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc
    http://hibernate.org/orm/documentation/5.1/migration/
    https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc

However after making the required changes, i am facing some runtime errors.

I took a very simple example model, where in my EntityModel looks like this:

EntityMetamodel(cemployees_create:[Attribute(name=LastName, type=string [non-identifier]),Attribute(name=FirstName, type=string [non-identifier]),Attribute(name=BirthDate, type=timestamp [non-identifier]),Attribute(name=HireDate, type=timestamp [non-identifier]),Attribute(name=Photo, type=binary [non-identifier]),Attribute(name=ReportsTo, type=cemployees_create [non-identifier,association]),Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])

However in version 5.2 when its trying to buildAttribute in AttributeFactory.java, its throwing the following exception:

java.lang.IllegalArgumentException: Expecting collection type [org.hibernate.type.BagType] at org.hibernate.metamodel.internal.AttributeFactory.determineCollectionType(AttributeFactory.java:937) at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.(AttributeFactory.java:786) at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.(AttributeFactory.java:767) at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:548) at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:77) at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:213) at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:220) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:297) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)

This is happening when its trying to build the Attribute for Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])

Just wanted to check if someone has faced this problem before or if any one knows resolutions for it.
The same thing works perfectly fine with Hibernate 4.3.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Fri Jun 02, 2017 10:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
You need to add the entity mappings to see what you are doing. If it's according to JPA specs, then it is an issue.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Mon Jun 05, 2017 11:56 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
I tried evaluating the code-path of Hibernate 4.3 for building the EntityAttribute for an association and it looks like this code works fine, with the same data:
Code:
public static NonIdentifierAttribute buildEntityBasedAttribute(EntityPersister persister, SessionFactoryImplementor sessionFactory, int attributeNumber, Property property, boolean lazyAvailable) {
        Type type = property.getValue().getType();
        PropertyFactory.NonIdentifierAttributeNature nature = decode(type);
        boolean alwaysDirtyCheck = type.isAssociationType() && ((AssociationType)type).isAlwaysDirtyChecked();
        switch(PropertyFactory.SyntheticClass_1.$SwitchMap$org$hibernate$tuple$PropertyFactory$NonIdentifierAttributeNature[nature.ordinal()]) {
        case 1:
            return new EntityBasedBasicAttribute(persister, sessionFactory, attributeNumber, property.getName(), type, (new Builder()).setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
        case 2:
            return new EntityBasedCompositionAttribute(persister, sessionFactory, attributeNumber, property.getName(), (CompositeType)type, (new Builder()).setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
        case 3:
        case 4:
        case 5:
            return new EntityBasedAssociationAttribute(persister, sessionFactory, attributeNumber, property.getName(), (AssociationType)type, (new Builder()).setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
        default:
            throw new HibernateException("Internal error");
        }
    }


however in hibernate 5.2, when i tried digging in deep, all i can find out is that it breaks in the following function:

Code:
public static PluralAttribute.CollectionType determineCollectionType(Class javaType) {
      if ( java.util.List.class.isAssignableFrom( javaType ) ) {
         return PluralAttribute.CollectionType.LIST;
      }
      else if ( java.util.Set.class.isAssignableFrom( javaType ) ) {
         return PluralAttribute.CollectionType.SET;
      }
      else if ( java.util.Map.class.isAssignableFrom( javaType ) ) {
         return PluralAttribute.CollectionType.MAP;
      }
      else if ( java.util.Collection.class.isAssignableFrom( javaType ) ) {
         return PluralAttribute.CollectionType.COLLECTION;
      }
      else if ( javaType.isArray() ) {
         return PluralAttribute.CollectionType.LIST;
      }
      else {
         throw new IllegalArgumentException( "Expecting collection type [" + javaType.getName() + "]" );
      }
   }


the input to the above function is org.hibernate.type.BagType since the ReporteesArr attribute is a collection kind of property but still it breaks by throwing the IllegalArguementException.

I am a bit new to this, but able to understand a bit of complexity. Can you help me out with the steps to debug this?
I specifically checked that the input values to both the functions are same.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Mon Jun 05, 2017 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
Quote:
You need to add the entity mappings to see what you are doing. If it's according to JPA specs, then it is an issue.


You still need to provide your mappings and say what you are trying to do since I have no idea what's the context of your issue.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Tue Jun 06, 2017 4:59 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
Actually those are being generated internally. I will try to get the details and post it here.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Tue Jun 06, 2017 5:04 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
Quote:
Actually those are being generated internally. I will try to get the details and post it here.


Are you talking about entity mappings? What do you mean they are generated internaly?

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Wed Jun 07, 2017 1:58 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
vlad wrote:
Quote:
Actually those are being generated internally. I will try to get the details and post it here.


Are you talking about entity mappings? What do you mean they are generated internaly?


The Project in which i am using it generate the entity Mappings internally. I will try to find out a way to get the details and post it here or create a sample project with the mapping and try to reproduce it and then paste it here.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Wed Jun 07, 2017 5:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
You should use our JPA test case templates to replicate it.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Tue Jun 13, 2017 6:53 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
vlad wrote:
You should use our JPA test case templates to replicate it.


This is the sample hbm.xml mapping file, which illustrates a simple example of self join.
Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cfsuite.orm.manual.relationship.self_join">
    <class entity-name="cemployees" table="Employees">
        <tuplizer class="coldfusion.orm.hibernate.CFCTuplizer" entity-mode="dynamic-map"/>
        <id column="EmployeeID" name="EmployeeID" type="integer">
            <generator class="native"/>
        </id>
        <property column="LastName" name="LastName" type="string"/>
        <property column="FirstName" name="FirstName" type="string"/>
        <property column="Title" name="Title" type="string"/>
        <property column="TitleOfCourtesy" name="TitleOfCourtesy" type="string"/>
        <property column="BirthDate" name="BirthDate" type="date"/>
        <property column="HireDate" name="HireDate" type="date"/>
        <property column="Address" name="Address" type="string"/>
        <property column="City" name="City" type="string"/>
        <property column="Region" name="Region" type="string"/>
        <property column="PostalCode" name="PostalCode" type="string"/>
        <property column="Country" name="Country" type="string"/>
        <property column="HomePhone" name="HomePhone" type="string"/>
        <property column="Extension" name="Extension" type="string"/>
        <property column="Photo" name="Photo" type="binary"/>
        <property column="Notes" name="Notes" type="string"/>
        <many-to-one column="ReportsTo" entity-name="cemployees" name="ReportsToObj"/>
        <property column="PhotoPath" name="PhotoPath" type="string"/>
        <bag cascade="all-delete-orphan" name="ReporteesArr">
            <key column="ReportsTo"/>
            <one-to-many entity-name="cemployees"/>
        </bag>
    </class>
</hibernate-mapping>


I will also try to simulate it using your JPA Test-case template, but till then if you find any issues with the mapping, please let me know.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Wed Jun 14, 2017 10:39 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
I have added the test-cases using the JPA test-cases here
https://github.com/hibernate/hibernate- ... es/pull/19

For keeping the changes minimum, i have left blank/null implementations for Getters/Setters and Tupulizers.

Please run both the test-cases and verify that with Hibernate 5.2 version while building the EntityAttribute we are getting this exception:

java.lang.IllegalArgumentException: Expecting collection type [org.hibernate.type.BagType]
at org.hibernate.metamodel.internal.AttributeFactory.determineCollectionType(AttributeFactory.java:930)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:779)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:760)
at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:541)
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:77)
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:213)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:220)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:490)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:200)
at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:187)
at org.hibernate.testing.junit4.TestClassMetadata.performCallbacks(TestClassMetadata.java:181)
at org.hibernate.testing.junit4.TestClassMetadata.performBeforeClassCallbacks(TestClassMetadata.java:172)
at org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:25)
at org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:25)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)


Let me know if you need any other details. I have created a JIRA issue here https://hibernate.atlassian.net/browse/HHH-11819


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Thu Jun 15, 2017 3:35 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
Thanks.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Sun Jun 18, 2017 10:12 pm 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
Team, any updates on this, this is a blocker for us and is preventing us from using the latest version of Hibernate. I logged https://hibernate.atlassian.net/browse/HHH-11819 as a blocker but its priority has been changed to Major by Chris Cranford. I just wanted to check if there is something else needed to be done from my end. Are there any workarounds that i can use to temporary resolve this until the issue gets fixed?


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Mon Jun 19, 2017 1:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
There are lots of issues to be fixed, and this one is only affecting your project since no one else found this use case over the past two years. You are also using a custom EntityTuplizer and dynamic-map which is definitely way beyond the typical usage.

If it's really a blocker for your team, then you can fix it and send us a Pull Request. That's the spirit of Open Source software, right?

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Mon Jun 19, 2017 1:44 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
vlad wrote:
There are lots of issues to be fixed, and this one is only affecting your project since no one else found this use case over the past two years. You are also using a custom EntityTuplizer and dynamic-map which is definitely way beyond the typical usage.

If it's really a blocker for your team, then you can fix it and send us a Pull Request. That's the spirit of Open Source software, right?


Sure, i can take a stab at this, just wanted to check if there are any related documents/forums which reflects the changes being done after 4.3 version or scanning through Jiras/code is the way to go?


Top
 Profile  
 
 Post subject: Re: Issues after upgrading hibernate version from 4.3 to 5.2
PostPosted: Mon Jun 19, 2017 4:57 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
I would just compare the old 4.3 code during debugging and see why it works, the switch to 5.2 and see why it does not work anymore.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 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.