簡體   English   中英

Hibernate和currentSession:“哎呀,我不要這些交易!”

[英]Hibernate and currentSession: “Heck, I don't want these transactions!”

我替換為:

sessionFactory.openSession();

帶有:

sessionFactory.getCurrentSession();

我為Hibernate添加了此配置:

<property name="hibernate.current_session_context_class">thread</property>

現在我得到這個錯誤:

failureorg.hibernate.HibernateException: createQuery is not valid without active transaction

使用currentTransaction之后,為什么還要使用beginTransaction()等等? 我不想使用交易...所以,我應該改變什么?

您使用的是getCurrentSession ,而不是currentTransaction 事務在Hibernate中不是可選的,您必須啟動一個事務。

您設置的配置導致自動為您打開一個會話,但該會話中沒有事務。

您可以通過Spring集成跳過事務的開始和提交,並將事務聲明為注釋驅動

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM