第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

spring-boot hibernate 雙向關(guān)聯(lián)查詢的坑

spring-boot hibernate 雙向關(guān)聯(lián)查詢的坑

暴躁的代碼 2017-08-07 23:55:18
有實體類user 和Info ,info對應(yīng)的表中有user的主鍵作為外鍵,需求是查詢info可以得到對應(yīng)的user,查詢user可以得到對應(yīng)的info。package?com.zxy.demo.entity; import?com.fasterxml.jackson.annotation.JsonIgnoreProperties; import?com.fasterxml.jackson.annotation.JsonIgnoreType; import?javax.persistence.*; @Entity public?class?User?{ ????@Id ????@GeneratedValue ????private?Integer?id; ????private?Integer?age; ????@OneToOne(mappedBy?=?"user",cascade?=?CascadeType.ALL) ????private?Info?userInfo; ????public?Integer?getId()?{ ????????return?id; ????} ????public?void?setId(Integer?id)?{ ????????this.id?=?id; ????} ????public?Integer?getAge()?{ ????????return?age; ????} ????public?void?setAge(Integer?age)?{ ????????this.age?=?age; ????} ????public?Info?getUserInfo()?{ ????????return?userInfo; ????} ????public?void?setUserInfo(Info?userInfo)?{ ????????this.userInfo?=?userInfo; ????} }package?com.zxy.demo.entity; import?javax.persistence.*; @Entity public?class?Info?{ ????@Id ????@GeneratedValue ????private?Integer?id; ????@Column(nullable?=?false) ????private?String?idCard; ????@OneToOne(cascade?=?CascadeType.ALL) ????@JoinColumn(unique?=?true) ????private?User?user; ????public?Integer?getId()?{ ????????return?id; ????} ????public?void?setId(Integer?id)?{ ????????this.id?=?id; ????} ????public?String?getIdCard()?{ ????????return?idCard; ????} ????public?void?setIdCard(String?idCard)?{ ????????this.idCard?=?idCard; ????} ????public?User?getUser()?{ ????????return?user; ????} ????public?void?setUser(User?user)?{ ????????this.user?=?user; ????} ????@Override ????public?String?toString()?{ ????????return?"Info{"?+ ????????????????"id="?+?id?+ ????????????????",?idCard='"?+?idCard?+?'\''?+ ????????????????",?user="?+?user?+ ????????????????'}'; ????} }當(dāng)調(diào)用jpa的findOne方法時,hibernate會注入user中的info,然后又一次注入info中的user,這樣很蠢。網(wǎng)上找到控制json解析的注解,這樣做還不如直接單項關(guān)聯(lián),治標(biāo)不治本。求一個解決方案!
查看完整描述

1 回答

?
特南克斯

TA貢獻(xiàn)14條經(jīng)驗 獲得超9個贊

控制json解析的深度就好了,沒有其他更合適的方法的。


你可以看一下這個回答:


spring-data-jpa多對多雙向關(guān)聯(lián),查詢的時候進(jìn)入死循環(huán)

查看完整回答
反對 回復(fù) 2017-11-01
  • 1 回答
  • 0 關(guān)注
  • 2808 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號