> > Could you please tell me the difference between commit(method of
> > Session) and flush(method of Transaction) in Hibernate?
>
> It is my understanding that flush causes Hibernate to execute
> SQL statements via JDBC while commit end up as a database
> commit. Two completely different things.
Can I simplely understande the difference as below:
1 flush execute the sql
2 commit close the connection
> I have read that one should use FlushMode.AUTO and never care
> about flush, but my experience with Hibernate is not sufficient
[quoted text clipped - 27 lines]
> And when you call commit should be determined by your
> business logic.
So, I should call the method "commit" in business layer but not in
persistence layer, is that right?
> Arne
Thanks.
Lew - 28 May 2007 05:36 GMT
Arne Vajhøj <a...@vajhoej.dk> wrote:
>> It is my understanding that flush causes Hibernate to execute
>> SQL statements via JDBC while commit end up as a database
>> commit. Two completely different things.
> Can I simplely understande the difference as below:
> 1 flush execute the sql
> 2 commit close the connection
A database commit does not close the connection.
I don't know about a Hibernate commit, but there was nothing in Arne's answer
to hint that it closes the connection.

Signature
Lew
Arne Vajhøj - 28 May 2007 15:41 GMT
>>> Could you please tell me the difference between commit(method of
>>> Session) and flush(method of Transaction) in Hibernate?
[quoted text clipped - 4 lines]
> Can I simplely understande the difference as below:
> 1 flush execute the sql
Yes.
> 2 commit close the connection
No. Commit commits the transaction (as the method name indicates).
>> And when you call commit should be determined by your
>> business logic.
> So, I should call the method "commit" in business layer but not in
> persistence layer, is that right?
Depends on your application design, but in most cases that will
be the correct place to do it. Only the business layer knows
if all changes that belongs to the transaction has been done
and whether it should be a commit or a rollback.
Arne
santax - 29 May 2007 02:34 GMT
> >>> Could you please tell me the difference between commit(method of
> >>> Session) and flush(method of Transaction) in Hibernate?
[quoted text clipped - 22 lines]
>
> Arne
OK,Thanks a lot.