posts - 325,  comments - 25,  trackbacks - 0
java提供了3种集合类:
Set:集合中的元素不须要排序且没有重复对象时用
List:当集合中允许有重复对象且需要按索引位置存取时用
Map:集合中需要使用键值存取对象时用
数据表:items picture tips videos
items:
id int(4) <pk>
itemno varchar(20)
itemname varchar(20)

picture表:
item_id int(4) <pk,fk>
keyname varchar(20) <pk>
picture varchar(100)

tips表:
item_id int(4) <pk,fk>
position int(4) <pk>
tip varchar(200)

videos表:
item_id int(4) <pk,fk>
video varchar(200) <pk>

持久化类:
public class Items implements Serializable{
    private Integer id;
    private String itemno;
    private String itemname;
    private Map picture=new HashMap();
    private List tips=new ArrayList();
    private Set videos=new HashSet();
    public Items(){
    }
}

hbm.xml
<hibernate-mapping package="com.lhb.vo">
    <class name="Items" table="items">
        <id name="id" column="id" type="integer">
            <generator class="native"/>
        </id>
        <property name="itemno" column="itemno" type="string"/>
        <property name="itemname" column="itemname" type="string"/>
        <map name="picture" table="picture" lazy="false">
            <key column="item_id'/>
            <!--指定一个代表键对象的字段名-->
            <index column="keyname" type="string"/>
            <!--指定一个与集合元素所对应的表字段名-->
            <element column="picture" type="string"/>
       </map>
        <list name="tips" table="tips" lazy="false">
            <key column="item_id"/>
            <!--指定个代表索引位置的字段名-->
            <index column="position" />
            <element column="tip" type="string"/>
        </list>
        <set name="videos' table="videos"  lazy="false">
            <key column="item_id"/>
            <element column="video" type="string" not-null="true"/>
        </set>
    </class>
</hibernate-mapping>
posted on 2008-05-25 22:01 长春语林科技 阅读(288) 评论(0)  编辑  收藏 所属分类: hibernate

只有注册用户登录后才能发表评论。


网站导航:
 
<2008年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

 

长春语林科技欢迎您!

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜