Cannot add foreign key constraint @ManyToMany @OneToMany

來源:互聯網
上載者:User

標籤:detail   匹配   man   _id   int   art   details   http   integer   

最近在使用shiro做許可權管理模組時,使用的時user(使用者)-role(角色)-resource(資源)模式,其中user-role 是多對多,role-resource 也是多對多。但是在使用spring data jpa 進行關聯映射資料庫時,報錯: Cannot add foreign key constraint。最後我這裡產生錯誤的的原因是 reource 表中主鍵ID類型是 bigint , 而role-resource 關聯表中的resource_id 是int型,所以報錯。


       其實在使用搭配spring data jpa 時,我resource 實體類中設定的主鍵ID是 Integer 類型,可是我的resource(資源)表是從其他地方copy來的,裡面的主鍵ID是bigint類型,所以導致在使用 @ManyToMany 註解時,映射的resource主鍵ID 和關聯表中的resource_id 類型不符。報錯。 這是我的出現問題的原因,在網上還找到了其他的一些原因,可參考:http://blog.csdn.net/yiwangxiblog/article/details/52269527

Cannot add foreign key constraint @ManyToMany @OneToMany

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.