Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Migration from 4.3.x to 5.x for method org.hibernate.cfg.Configuration.getClassMapping(className)

Tags:

In Hibernate 4.3.x, there is a method getClassMapping(className) of class org.hibernate.cfg.Configuration. But in Hibernate 5.x, this getClassMapping(className) method is removed from Configuration class.

What will be the code substitution in Hibernate-5?

Please help on this migration issue.

like image 541
Nirav Patel Avatar asked Sep 25 '15 10:09

Nirav Patel


1 Answers

I posted to Broadleaf Commerce because they also needed PersistentClass:

I've been tooling with Hibernate 5, and some of these changes .... To get metadata now use the Serviceloader:

package org.broadleafcommerce.openadmin.server.dao;  import org.hibernate.boot.SessionFactoryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryBuilderFactory; import org.hibernate.boot.spi.SessionFactoryBuilderImplementor;  public class EntityMetaData implements SessionFactoryBuilderFactory {      private static final ThreadLocal<MetadataImplementor> meta = new ThreadLocal<>();      @Override     public SessionFactoryBuilder getSessionFactoryBuilder(MetadataImplementor metadata, SessionFactoryBuilderImplementor defaultBuilder) {         meta.set(metadata);         return defaultBuilder;     }      public static MetadataImplementor getMeta() {         return meta.get();     } } 

You will need the file:

/resources/META-INF/services/org.hibernate.boot.spi.SessionFactoryBuilderFactory 

with the fully qualified class name, which in my example is:

org.broadleafcommerce.openadmin.server.dao.EntityMetaData 
like image 181
John Avatar answered Sep 22 '22 09:09

John