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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With