- public class HibernateTest {
- public static void main(String[] args){
- File file = new File("src/hibernate.cfg.xml");
- Configuration cfg = new Configuration();
- cfg.configure(file);
- SessionFactory sessionFactory = cfg.buildSessionFactory();
- Session session = sessionFactory.getCurrentSession();
- // Transaction ts = session.getTransaction();
- // ts.begin();
- Transaction ts = session.beginTransaction();
- Book book = (Book) session.get(Book.class, 2);
- // System.out.println(book.getName() + ", " + book.getPrice());
- ts.commit();
- System.out.println(book);
- }
- }
复制代码 没有抛异常,但是结果为null
|
|