我已经创建了一个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