标题:hibernate配置set时主键的问题。
取消只看楼主
shenyun345
Rank: 2
等 级:论坛游民
帖 子:32
专家分:10
注 册:2009-7-13
结帖率:50%
 问题点数:0 回复次数:0 
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集合没有主键约束啊。
搜索更多相关主题的帖子: void private package public 
2011-09-16 10:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-350041-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.701313 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved