外键
11:13:26,473 ERROR SchemaUpdate:212 - Unsuccessful: alter table itcast_department add index FKB56F87C78F69840 (parentId), add constraint FKB56F87C78F69840 foreign key (parentId) references itcast_department (id)
11:13:26,474 ERROR SchemaUpdate:213 - Can't create table '.\oa_2016\#sql-70c_5.frm' (errno: 150)
11:13:26,606 ERROR SchemaUpdate:212 - Unsuccessful: alter table itcast_user add index FK4ADEC008AF5C8E8 (departmentId), add constraint FK4ADEC008AF5C8E8 foreign key (departmentId) references itcast_department (id)
11:13:26,606 ERROR SchemaUpdate:213 - Can't create table '.\oa_2016\#sql-70c_5.frm' (errno: 150)
11:13:26,720 ERROR SchemaUpdate:212 - Unsuccessful: alter table itcast_user_role add index FK9C95CD5587E23CF0 (roleId), add constraint FK9C95CD5587E23CF0 foreign key (roleId) references itcast_role (id)
11:13:26,720 ERROR SchemaUpdate:213 - Can't create table '.\oa_2016\#sql-70c_5.frm' (errno: 150)
11:13:26,816 ERROR SchemaUpdate:212 - Unsuccessful: alter table itcast_user_role add index FK9C95CD558D37925A (userId), add constraint FK9C95CD558D37925A foreign key (userId) references itcast_user (id)
user.hbm.xml
<!-- department与Department 多对一 -->
<many-to-one name="department" class="Department" column="departmentId"></many-to-one>
<!-- role与Role 多对多 -->
<set name="roles" table="itcast_user_role">
<key column="userId" ></key>
<many-to-many class="Role" column="roleId"></many-to-many>
</set>
---------------------------------------------------------------------------------------
role.hbm.xml
<!-- 与user 多对多 -->
<set name="users" table="itcast_user_role">
<key column="roleId" ></key>
<many-to-many class="User" column="userId"></many-to-many>
</set>
---------------------------------------------------------------------------------------------
department.hbm.xml
<!-- users属性与user 一对多 -->
<set name="users">
<key column="departmentId"></key>
<one-to-many class="User"/>
</set>
<!-- parent属性与department(上级)多对一 -->
<many-to-one name="parent" class="Department" column="parentId"></many-to-one>
<!-- chirldren属性与department下级 一对多 -->
<set name="chirldren">
<key column="parentId"></key>
<one-to-many class="Department"/>
</set>
---------------------------------------------------------------------------------------------
posted on 2016-08-02 11:38 huxihua2006 阅读(164) 评论(1) 编辑 收藏 举报