简体   繁体   中英

how to make sure that hibernate committed a transaction?

I've got a very weird behavior, in my java (spring) application, I've a case where i save an object using hibernateTemplate, then calling a thread which try to get this object again using hibernateTemplate, if am running in debug mode every thing is working fine, but when am not, it most of time give me null pointer exception, as the object returned back from the second call in the thread returns a null object,

so bottom-line here is: i think hibernate didn't commit its transaction, before the thread is started,

so how to make sure that the object is saved i DB before the thread starts,

Regards,

执行flush()应该可以完成这项工作。

so bottom-line here is: I think hibernate didn't commit its transaction, before the thread is started

Why would Hibernate do that? Actually, Hibernate doesn't provide automatic transaction handling.

so how to make sure that the object is saved i DB before the thread starts,

Commit the transaction started in Thread #1 before starting the new Thread #2.

Without more details about your Spring/Hibernate setup and the transaction handling, it will be hard to get a more detailed answer IMO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM