我是Hibernate的初學者,在映射3個包含2個實體的表時發現問題。如何在聯合表中使用Hibernate XML映射實體
的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)
);
當前映射XMLS
User.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>
Role.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文件。謝謝
這真的不清楚你在這裏問什麼。問題是什麼?您是否正在努力繪製這些類型之間的關聯或不清楚HBM文件與java類文件的關係? – EdC