package com.gontuseries.hibernate;
导入org.hibernate.Session; 导入org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
导入java.text.Annotation;
导入org.hibernate.Session; 导入org.hibernate.SessionFactory;
导入com.fasterxml.classmate.AnnotationConfiguration;
公共类主要{
public static void main(String[] args) {
Student_Info obj = new Student_Info();
obj.setName("hello1");
obj.setRollno(4);
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
// this would save the Student_Info object into the database
session.save(obj);
session.getTransaction().commit();
session.close();
sessionFactory.close();
}
}
答案 0 :(得分:0)
可能的问题是您没有按预期映射您的Student_Info,需要使用标记@Entity,这样JPA便知道您要保留该对象。
@Entity
公共课程Student_Info {
}