[英]spring boot migration from 1.5 to 2.1, hibernate errors
我將 spring 引導版本從 1.5 遷移到 2.1。 現在開始使用 hibernate 版本 5.3.12 與之前的 5.0.12。 現在我看到很多以前未捕獲的 hibernate 異常,例如:
在 @OneToOne 映射注釋上,因為缺少 Cascade 類型:
ERROR: update or delete on table violates foreign key constraint
當我試圖通過以下方式獲取記錄時,在 @Test 上:repository.findById()
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
on old project with hibernate 5.0.12 these errors don't appear, but as soon as I switch to new spring boot project, these start appearing with the only change factor being upgraded spring dependencies and hibernate version.
嘗試對此進行搜索,但找不到任何關於此 hibernate 版本與以前版本相比發生了什么變化的具體內容。 有沒有人遇到過類似的問題? 任何幫助或提示將不勝感激,因為我堅持這些。
因此,您嘗試將對象序列化到服務層之外的所有原因。 (事務注解)
@Entity
class A {
@OneToOne(fetch = FetchType.LAZY)
private B b;
}
如果您嘗試序列化 class A out of service layer,那么 hibernate session 已經關閉,並且您有提到的異常
檢查這個https://www.baeldung.com/hibernate-lazy-eager-loading
修復它的正確方法是組裝 DTO(數據傳輸對象)並將其從服務層返回到 controller。 然后序列化 DTO。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.