hibernate session.save() does not reflect in database

后端 未结 9 2121
臣服心动
臣服心动 2020-12-08 14:30

According to my understanding in hibernate (please confirm)

1- You have to session.close() if you get it by getSessionFactory().openSession()

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 15:15

    I was also trying to understand the point: save() can perform Insert operation outside transaction boundary so I did something like this

    SessionFactory factory = new Configuration().configure()
                        .buildSessionFactory();
                Session session = factory.openSession();
    
                session.save(user);
    
                session.close();
    

    But data not inserted in database.So I again tried this and now it worked for me and data inserted sucessfully:

    in configuration file:

      true
    

    and in java code:

        SessionFactory factory = new Configuration().configure()
                .buildSessionFactory();
        Session session = factory.openSession();
    
        session.save(user);
    
        session.flush();
        session.close();
    

提交回复
热议问题