jian_xiao wrote:
Hibernate can configured to use JDBC transaction or JTA transaction,but
the two way are inconsisent. Consider the following codes:
in a JDBC transaction:
Sorry, I don't understand your point. AFAIK, the hibernate transaction API is a wrapper around either the JDBC transaction API or JTA, depending on how you configure it. So if you configure hibernate to use JTA transactions, you can use the Hibernate transaction API and behind the scene JTA is used.
A few other points:
1. When using the Hibernate API, committing a transaction automatically flushes the session, so there is no need to explicitly call flush().
2. You second example seems to use the session-per-operation antipattern. Unless you have _very_ good reasons to do otherwise, I think it would be a good idea to follow the guidelines at
http://www.hibernate.org/168.html3. Using declarative transactions, supported e.g. by the spring framework, you would avoid a lot of boring and repetetive code.
Quote:
So I must choose a type of transaction hardcoded in my program and change between them in the future are become impossible,is it?
Hey, as your very own signature says:
Quote:
Nothing is impossible to a willing heart
;-)