What's flushed by Hibernate's Session.flush()
What exactly happens when I call Session.flush() on an open hibernate session? Are all entities that I changed (persisted, deleted, updated) with save/update/delete written to the database, or are ALL entities in the session written to the database, also if I havn't called update, etc. on them?
I find lots of Hibernate resources talking about this, but nothing gives me exactly the precise answer I am looking for.
A si开发者_开发问答mple examples:
class A {
@OneToOne
public B b;
public int x;
}
class B {
@OneToOne(mappedBy="b")
public B b;
public int y;
}
// Example
A a = aDao.load(...);
a.x = 20;
b.y = 15;
aDao.update(a);
// Question: Will this update b's value to 15 in the database?
session.flush();
If B will be updated in the example above, how can I prevent it?
Thanks for your help!
All changes are written to the database. Objects that you didn't create/modify/delete aren't saved.
I'm not sure what happens for things like obj.setName(obj.getName())
(i.e. when you touch a property but don't change it).
精彩评论