方法org.hibernate.cfg.Configuration.getClassMapping(className)从4.3.x到5.x的Hibernate迁移 [英] Hibernate Migration from 4.3.x to 5.x for method org.hibernate.cfg.Configuration.getClassMapping(className)

查看:912
本文介绍了方法org.hibernate.cfg.Configuration.getClassMapping(className)从4.3.x到5.x的Hibernate迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hibernate 4.3.x中,有一个类 org.hibernate.cfg.Configuration 的方法 getClassMapping(className) C>。
但是在Hibernate 5.x中,这个 getClassMapping(className)方法从 Configuration class中移除。



Hibernate-5中的代码替换是什么?



请帮助解决这个迁移问题。

因为他们还需要 PersistentClass


我一直在用Hibernate 5进行工具化,其中一些变化......
现在使用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实现SessionFactoryBuilderFactory {

private static final ThreadLocal< MetadataImplementor> meta = new ThreadLocal<>();

@Override
public SessionFactoryBuilder getSessionFactoryBuilder(MetadataImplementor元数据,SessionFactoryBuilderImplementor或defaultBuilder){
meta.set(metadata);
返回defaultBuilder;


public static MetadataImplementor getMeta(){
return meta.get();


您将需要以下文件:

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

与完全限定的类名称,在我的例子中是:

  org.broadleafcommerce.openadmin.server.dao.EntityMetaData 


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

这篇关于方法org.hibernate.cfg.Configuration.getClassMapping(className)从4.3.x到5.x的Hibernate迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆