数据库结构
映射文件:
CREATE
TABLE
`team3` (
`id` varchar ( 50 ) NOT NULL ,
`name` varchar ( 50 ) default NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = gb2312;
CREATE TABLE `member3` (
`id` varchar ( 50 ) NOT NULL ,
`name` varchar ( 50 ) default NULL ,
`age` varchar ( 50 ) default NULL ,
`role` varchar ( 50 ) default NULL ,
`scene` varchar ( 50 ) default NULL ,
`team` varchar ( 50 ) default NULL ,
`bestChoice` varchar ( 50 ) default NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = gb2312;
`id` varchar ( 50 ) NOT NULL ,
`name` varchar ( 50 ) default NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = gb2312;
CREATE TABLE `member3` (
`id` varchar ( 50 ) NOT NULL ,
`name` varchar ( 50 ) default NULL ,
`age` varchar ( 50 ) default NULL ,
`role` varchar ( 50 ) default NULL ,
`scene` varchar ( 50 ) default NULL ,
`team` varchar ( 50 ) default NULL ,
`bestChoice` varchar ( 50 ) default NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = gb2312;
实体类:
package
mapcompoistindex;
import java.util.HashMap;
import java.util.Map;
public class Team {
private String id;
private String name;
private Map members = new HashMap();
public String getId() {
return id;
}
public void setId(String id) {
this .id = id;
}
public Map getMembers() {
return members;
}
public void setMembers(Map members) {
this .members = members;
}
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
}
package mapcompoistindex;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Member {
private String id;
private String name;
private Position postition;
private Team team;
private String age;
public String getAge() {
return age;
}
public void setAge(String age) {
this .age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
public Position getPostition() {
return postition;
}
public void setPostition(Position postition) {
this .postition = postition;
}
public String getId() {
return id;
}
public void setId(String id) {
this .id = id;
}
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this .team = team;
}
}
package mapcompoistindex;
public class Position {
private String role;
private String scene;
private Member bestChoice;
public Member getBestChoice() {
return bestChoice;
}
public void setBestChoice(Member bestChoice) {
this .bestChoice = bestChoice;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this .role = role;
}
public String getScene() {
return scene;
}
public void setScene(String scene) {
this .scene = scene;
}
}
import java.util.HashMap;
import java.util.Map;
public class Team {
private String id;
private String name;
private Map members = new HashMap();
public String getId() {
return id;
}
public void setId(String id) {
this .id = id;
}
public Map getMembers() {
return members;
}
public void setMembers(Map members) {
this .members = members;
}
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
}
package mapcompoistindex;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Member {
private String id;
private String name;
private Position postition;
private Team team;
private String age;
public String getAge() {
return age;
}
public void setAge(String age) {
this .age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
public Position getPostition() {
return postition;
}
public void setPostition(Position postition) {
this .postition = postition;
}
public String getId() {
return id;
}
public void setId(String id) {
this .id = id;
}
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this .team = team;
}
}
package mapcompoistindex;
public class Position {
private String role;
private String scene;
private Member bestChoice;
public Member getBestChoice() {
return bestChoice;
}
public void setBestChoice(Member bestChoice) {
this .bestChoice = bestChoice;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this .role = role;
}
public String getScene() {
return scene;
}
public void setScene(String scene) {
this .scene = scene;
}
}
映射文件:
<?
xml version="1.0" encoding="utf-8"
?>
<! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
< hibernate-mapping package ="mapcompoistindex" >
< class name ="Team" table ="team3" >
< id name ="id" column ="id" >
< generator class ="uuid.hex" ></ generator >
</ id >
< property name ="name" column ="name" />
< map name ="members" inverse ="false" cascade ="save-update" >
< key column ="team" />
< composite-index class ="Position" >
< key-property name ="role" ></ key-property >
< key-property name ="scene" ></ key-property >
< key-many-to-one name ="bestChoice" class ="Member" ></ key-many-to-one >
</ composite-index >
< one-to-many class ="Member" />
</ map >
</ class >
</ hibernate-mapping >
<? xml version="1.0" encoding="utf-8" ?>
<! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
< hibernate-mapping package ="mapcompoistindex" >
< class name ="Team" table ="team3" >
< id name ="id" column ="id" >
< generator class ="uuid.hex" ></ generator >
</ id >
< property name ="name" column ="name" />
< map name ="members" inverse ="false" cascade ="save-update" >
< key column ="team" />
< composite-index class ="Position" >
< key-property name ="role" ></ key-property >
< key-property name ="scene" ></ key-property >
< key-many-to-one name ="bestChoice" class ="Member" ></ key-many-to-one >
</ composite-index >
< one-to-many class ="Member" />
</ map >
</ class >
</ hibernate-mapping >
<? xml version="1.0" encoding="utf-8" ?>