hibernate映射基本類型的集合

來源:互聯網
上載者:User
這些代碼純粹是為了示範使用hibernate映射基本類型的集合資料。包括list、set、數組、map等先看一個簡單的pojo對象package com.hsj.domain;import java.util.List;import java.util.Map;import java.util.Set;public class Box {private Long id;private Set<String> set;private List<Integer> list;private Map<String, String> map;private String[] strs;public Set<String> getSet() {return set;}public void setSet(Set<String> set) {this.set = set;}public List<Integer> getList() {return list;}public void setList(List<Integer> list) {this.list = list;}public Map<String, String> getMap() {return map;}public void setMap(Map<String, String> map) {this.map = map;}public String[] getStrs() {return strs;}public void setStrs(String[] strs) {this.strs = strs;}public Long getId() {return id;}public void setId(Long id) {this.id = id;}}然後是映射的設定檔<?xml version="1.0"?><!DOCTYPE hibernate-mapping SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="com.hsj.domain"><class name="Box" table="t_box"><id name="id" type="long"><generator class="native"/></id><set name="set" table="t_set" ><key column="box_id"/><element type="string" column="username" /></set><list name="list" table="t_list" ><key column="box_id"/><list-index column="orders"/><element type="int" column="numbers"/></list><map name="map" table="t_map"><key column="box_id"/><index  type="string" column="name"/><element type="string" column="value"/></map><array name="strs" table="t_strs"><key column="box_id"/><list-index column="orders"/><element type="string" column="arrs"/></array></class></hibernate-mapping>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.