简体   繁体   English

在Hibernate中创建会话

[英]Create Session in Hibernate

package session;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import java.util.*;
public class SessionCreate {

private static final SessionFactory sessionFactory = buildSessionFactory1();

private static SessionFactory buildSessionFactory1() {
Configuration configuration = new Configuration().configure(); // configuration
                                                                // settings
                                                                // from
                                                                // hibernate.cfg.xml

StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();


serviceRegistryBuilder.applySettings(configuration.getProperties());

ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();

return configuration.buildSessionFactory(serviceRegistry);
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
 }

public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
 }

}

I had JRE8 installed on my computer and I restored it to JRE7 but still i get errors. 我在计算机上安装了JRE8,将其还原到JRE7,但仍然出现错误。 Please help me with this. 请帮我解决一下这个。 This is the only error I am getting: "Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor" error for SessionCreate Class. 这是我得到的唯一错误:SessionCreate类的“默认构造函数未定义隐式超级构造函数Object()。必须定义一个显式构造函数”错误。 What kind of constructor should I make? 我应该做什么样的构造函数? Another error for configuration.Properties() method :"The type java.util.Properties cannot be resolved. It is indirectly referenced from required .class files" configuration.Properties()方法的另一个错误:“类型java.util.Properties无法解析。它是从所需的.class文件中间接引用的”

I have searched a lot for the solution.. Thanks. 我已经搜索了很多解决方案..谢谢。

如果您最近更改了JRE版本,则可能必须清理并重新编译代码,因为.class文件在这两个版本之间可能不兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM