问题描述:

Currently, I am having this code to insert a Product object and it works totally fine!

public void insertProduct(Product product) {

Session session = this.databaseDriver.openSession();

Transaction transaction = session.beginTransaction();

session.save(product);

transaction.commit();

session.close();

}

However, this code does not seem to work:

public void insertProduct(Product product) {

Session session = this.databaseDriver.openSession();

session.save(product);

session.flush();

session.close();

}

What would be the reason for this? Neither does it give me any errors nor insert the data.

网友答案:

In hibernate even after calling session.flush it only updates an existing instance of the object not add a new one .Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.

相关阅读:
Top