我已經創建了一個UserObject和RoleObject來表示我的應用程序中的用戶。我試圖使用CRUD而不是原始JDBC的休眠。我已成功從數據庫中檢索信息,但無法創建新用戶。我收到以下錯誤。堅持用戶使用休眠
org.springframework.web.util.NestedServletException: Request processing failed; nested
exception is org.springframework.dao.DataIntegrityViolationException: could not insert:
[com.dc.data.UserRole]; nested exception is
org.hibernate.exception.ConstraintViolationException: could not insert:
[com.dc.data.UserRole]
我的數據的基礎上被定義爲如下:
用戶表,表管理局和當局表。權威表是用戶和權威的聯合。
我對UserObjec Hibernate映射如下:
<class name="com.dc.data.UserRole" table="authority">
<id name="id" column="authId">
<generator class="native" />
</id>
<property name="roleName">
<column name="authority" length="60" not-null="true" />
</property>
</class>
如何,我需要改變我的映射或對象結構要能夠堅持新:
...
<set name="roles" table="authorities" cascade="save-update" lazy="false" >
<key column="userId" />
<one-to-many class="com.dc.data.UserRole"/>
<many-to-many class="com.dc.data.UserRole" column="authId" />
</set>
</class>
...
UserRole的如下映射用戶?
這絕對解決了這個問題。謝謝! – IaCoder 2008-12-08 03:09:17