hibernate配置set时主键的问题。
java代码package
import java.util.List;
import java.util.Map;
import java.util.Set;
public class CollectionM {
private int id;
private String cname;
private Set setV;
private List listV;
private String[] arrayV;
private Map mapV;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCname() {
return cname;
}
public void setCname(String cname) {
= cname;
}
public Set getSetV() {
return setV;
}
public void setSetV(Set setV) {
this.setV = setV;
}
public List getListV() {
return listV;
}
public void setListV(List listV) {
this.listV = listV;
}
public String[] getArrayV() {
return arrayV;
}
public void setArrayV(String[] arrayV) {
this.arrayV = arrayV;
}
public Map getMapV() {
return mapV;
}
public void setMapV(Map mapV) {
this.mapV = mapV;
}
}
下面是配置文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.
<hibernate-mapping>
<class name="
<id name="id">
<generator class="native"></generator>
</id>
<property name="cname"></property>
<list name="listV" table="t_list">
<key column="listid"></key>
<list-index column="list_index"></list-index>
<element type="string" column="list_v"></element>
</list>
<array name="arrayV" table="t_array">
<key column="aid"></key>
<list-index column="array_index"></list-index>
<element type="string" column="array_v"></element>
</array>
<map name="mapV" table="t_map">
<key column="mid"></key>
<map-key type="string" column="m_key"></map-key>
<element type="string" column="m_value"></element>
</map>
<set name="setV" table="t_set">
<key column="setid"></key>
<element type="string" column="set_v"></element>
</set>
</class>
</hibernate-mapping>
下面是运行后数据库里面的各表信息
mysql> desc t_set;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| setid | int(11) | NO | MUL | NULL | |
| set_v | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.05 sec)
mysql> desc t_map;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| mid | int(11) | NO | PRI | NULL | |
| m_value | varchar(255) | YES | | NULL | |
| m_key | varchar(255) | NO | PRI | NULL | |
+---------+--------------+------+-----+---------+-------+
为什么别的集合都有主键约束,set集合没有主键约束啊。