[英]Hibernate 3.6 configuration with Spring 2.5
I am currently working on a Maven project with dependencies on Spring 2.5 and Hibernate 3.6. 我目前正在开发一个依赖于Spring 2.5和Hibernate 3.6的Maven项目。 However, I am experiencing a problem on this portion of code:
但是,我在这部分代码上遇到问题:
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
static
{
try
{
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
catch (HibernateException e)
{
e.printStackTrace();
}
}
The following are the problems: 问题如下:
Are there any alternative code for this without upgrading and downgrading to another Spring and Hibernate versions? 是否有任何替代代码, 而无需升级和降级到另一个Spring和Hibernate版本?
Go to maven search repo sites like : http://mvnrepository.com/search?q=hibernate 转到Maven搜索回购网站,例如: http ://mvnrepository.com/search?q= hibernate
and search for "hibernate", and you'll see relevant version mvn-dependency-snippets: 并搜索“休眠”,您将看到相关的版本mvn-dependency-snippets:
http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager/3.6.10.Final http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager/3.6.10.Final
copy paste it to your pom, it should work. 复制粘贴到您的pom,它应该可以工作。
Got it! 得到它了!
I used: 我用了:
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.