注意细节

import org.hibernate.*;
import hibernate.HibernateSessionFactory;
public class testhibernate {

public static void main(String[] args) {

Session session =HibernateSessionFactory.getSession();

Transaction tran = session.beginTransaction();
Login login = new Login();

login.setId(10);
login.setName("aaaaaa");
login.setAge(20);
System.out.println(session);
session.save(login);
tran.commit();
System.out.println("数据添加成功!");
}
}

如果不写事务写不进数据库的

你可能感兴趣的:(Hibernate)