我在代码中使用了 SessionFactory 和 Configuration()。我做了 Eclipse 建议导入,但是当将鼠标放在“SessionFactory”上时,我的 Eclipse 显示了建议,例如创建本地变量“SessionFactory”并创建一个字段、SessionFactory 的参数并删除分配。
import java.net.URL;
import org.xml.sax.SAXException;
我尝试了上述导入,但它对我不起作用
public class CreateStudentDemo {
public static void main(String[] args) {
// Create Session Factory
SessionFactory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Student.class)
.buildSessionFactory();
// Create Session
Session session = factory.getCurrentSession();
try {
//use session object to save java object
}
finally{
factory.close();
}
适合 SessionFactory 和 Configuration() 的导入或 JAR 文件
最佳答案
我认为jar没有问题更改代码如下
public static void main(String[] args) {
// Create Session Factory
SessionFactory factory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Student.class)
.buildSessionFactory();
// Create Session
Session session = factory.getCurrentSession();
}
关于java - SessionFactory 和 Configuration() 的合适导入和 JAR 文件是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56471491/