我是 Hibernate 的初学者,在将 3 个表与 2 个实体映射时发现了一个问题。
SQL 代码:
CREATE TABLE users (
userid int unsigned auto_increment,
username varchar(20) not null,
password varchar(64) not null,
primary key (userid)
);
CREATE TABLE roles (
roleid int unsigned auto_increment,
rolename varchar(10) not null,
description varchar(255) not null
primary key (roleid)
);
CREATE TABLE userroles (
userid int unsigned not null,
roleid int unsigned not null,
primary key (userid,roleid),
foreign key (userid) references users (userid),
foreign key (roleid) references roles (roleid)
);
当前映射 xml
用户.hbm.xml
<class name="com.model.User" table="users">
<id name="userId" column="userid">
<generator class="native"/>
</id>
<property name="userName" column="username"/>
<property name="password" column="password"/>
</class>
角色.hbm.xml
<class name="com.model.Role" table="roles">
<id name="roleId" column="roleid">
<generator class="native"/>
</id>
<property name="roleName" column="rolename"/>
<property name="description" column="description"/>
</class>
还请告知如何创建实体 java 文件。谢谢