开发者

hibernate transaction, commit not valid without active transaction

first of all, sorry if my english is so bad, i am new in using hibernate so there is some question that i want to ask to all of senior. here is the condition: i am using zk for the view, in one view i have a toolbar that have (add),(save),(cancel) button. so what i want is when user klik (add) hibernate will start a new transaction and then user insert some data after that user klik (save). in this (save) button event hibernate will call commit to insert the data to database.

the problem is when user klik save, it error with message "commit not valid without active transaction" after 1 trace the program flow i found that when user klik the (save) button, the tran开发者_如何学运维saction that i have started previously is not active anymore.

## what i want to ask is why the transaction is inactive while i'm not commit it yet? ##

i'am using spring with hibernate and hibernate.current_session_context_class = Thread

thank's for the help


It's impossible to tell without seeing the code. But what you want to do is a very bad idea. Don't do it. A transaction should be as short as possible. Letting a transaction open for a long time (your user could take a while between the Add and the Save clicks) leaves a connection open and not usable by other concurrent users, will probably lead to a timeout anyway, and could lock some database rows or tables, making all the other users wait for your transaction to finish.

The insertion in database and the commit should be done only when the user clicks the Save button. The modifications done by the Add button should not be persisted in database, but be stored in memory, until the user clicks Save.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜