寻找一个不被淘汰的session-factory

寻找一个不被淘汰的session-factory,第1张

寻找一个不被淘汰的session-factory

当我有一些时间使软件现代化时,我决定做出一些努力并进行了一些研究:

http://www.prejava.net/frameworks/hibernate/building-hibernate-
sessionfactory-from-service-
registry
提供了一种现代化的方法

HibernateUtil

import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;public class HibernateUtil {private static SessionFactory sessionFactory;public static SessionFactory getSessionFactory() {    if (sessionFactory == null) {        Configuration configuration = new Configuration().configure();        ServiceRegistryBuilder registry = new ServiceRegistryBuilder();        registry.applySettings(configuration.getProperties());        ServiceRegistry serviceRegistry = registry.buildServiceRegistry();        sessionFactory = configuration.buildSessionFactory(serviceRegistry);     }    return sessionFactory;}}

即使此版本似乎也可以工作:

import java.util.logging.Level;import java.util.logging.Logger;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;public class HibernateUtil {private static final SessionFactory sessionFactory;static {    try {        Configuration cfg = new Configuration();        sessionFactory = cfg.configure("hibernate.cfg.xml").buildSessionFactory();    } catch (Throwable ex) {        Logger.getLogger(HibernateUtil.class.getName()).log(Level.SEVERE, null, ex);        throw new ExceptionInInitializerError(ex);    }}public static SessionFactory getSessionFactory() {    return sessionFactory;}

}

但是我的问题是我不想将新版本与旧库集成在一起。更新后,我遇到了

java.lang.NoSuchMethodError:org.hibernate.annotations.common.reflection.java.JavaReflectionManager.injectClassLoaderDelegate(Lorg
/ hibernate / annotations / common / reflection / ClassLoaderDelegate;)V

经常。烦死了 通常Mkyong提供了很好的解决方案,但是在我的情况下,他写了Stackoverflow的相反解决方案…

因此,我搜索了一些存储库,发现了一个非常简单的解决方案(比较:http :
//hibernate.org/orm/downloads/):

<!-- HIBERNATE --><dependency>    <groupId>org.hibernate</groupId>    <artifactId>hibernate-core</artifactId>    <version>5.0.0.Final</version></dependency>

其他一些小问题使我停了下来:在中,

hibernate.cfg.xml
我不得不将行从更改
update
auto

<property name="hbm2ddl.auto">auto</property>

将其与我的旧pom.xml进行比较…-那时我与Hibernate进行了第一次“接触”,并添加了所有似乎有用的东西,直到它起作用为止。在这样做之后,我停止接触它了……差不多两年了……永远不要换一支“获胜”的球队,对吗?

<dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>4.0.2.Final</version>        </dependency>        <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.12.Final</version> <exclusions>     <exclusion>         <artifactId>hibernate-commons-annotations</artifactId>         <groupId>org.hibernate.common</groupId>     </exclusion>     <exclusion>         <artifactId>hibernate-jpa-2.1-api</artifactId>         <groupId>org.hibernate.javax.persistence</groupId>     </exclusion>     <exclusion>         <artifactId>hibernate-commons-annotations</artifactId>         <groupId>org.hibernate</groupId>     </exclusion> </exclusions>        </dependency>        <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.1.8.Final</version> <exclusions>     <exclusion>         <artifactId>hibernate</artifactId>         <groupId>org.hibernate</groupId>     </exclusion>     <exclusion>         <artifactId>hibernate-annotations</artifactId>         <groupId>org.hibernate</groupId>     </exclusion>     <exclusion>         <artifactId>hibernate-commons-annotations</artifactId>         <groupId>org.hibernate</groupId>     </exclusion>     <exclusion>         <artifactId>hibernate-jpa-2.1-api</artifactId>         <groupId>org.hibernate.javax.persistence</groupId>     </exclusion> </exclusions>        </dependency>        <dependency><dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>3.2.0.Final</version>        </dependency>        <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.1.Final</version>        </dependency>        <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-jpamodelgen</artifactId> <version>1.1.1.Final</version> <scope>provided</scope>        </dependency>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5499748.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存