關於hibernate實體類

來源:互聯網
上載者:User

標籤:des   io   java   for   sp   資料   on   cti   ad   

  給的資料庫模型是sql2005的,然後在powerdesigner把資料庫模型改成mysql的去建實體,建不上,貌似好多東西要改。

  要做以下幾件事:

  1,加上uuid的東西,產生唯一id,類型是String,Java中實體類主鍵上加

  @GenericGenerator(name="systemUUID",strategy="uuid")
  @GeneratedValue(generator="systemUUID")

  有些用自增的感覺會比較好些。

  2,要把int類型改成integer,因為int的預設值是0,插入會有預設值。

  3,貌似hibernate直接產生的關係都是一對多的,一對一的忘記怎麼弄了,還有多對多的還要建第三方表,明天要研究研究這個。

  4,每個表的遞增流水號不知道是幹什麼的。

  其他:

[11-05 13:43:36] [RMI TCP Connection(3)-127.0.0.1] [ERROR][org.springframework.web.context.ContextLoader-331]-Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory‘ defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.shinowit.entity.TMeStockInfo column: MerchandiseID (should be mapped with insert="false" update="false")

百度說是不同的屬性對應為相同的欄位,重複映射同一個欄位,就會出現這個錯誤;

還沒解決。


解決方案:
確實是不同的屬性對應了相同的欄位,比如之前有一個

private int roleId;

我又加了一個一對多的關係

privateRole role;

並且Role裡有roleId,這就重複映射了,在通過表建實體的時候不要勾選roleId就可以了。

關於hibernate實體類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.