12 집합 맵 맵 집합
5992 단어 map
Map
Map
name
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="vo.util.bean">
<class name="Employee">
<id name="id">
<generator class="native"/>
</id>
<property name="name" unique="true"/>
<many-to-one name="derpartment" column="depaer_id" not-null="true"/>
</class>
</hibernate-mapping>
unique
package vo.util.bean;
/**
*
* @author Administrator
*
*/
public class Employee {
private int id;
private String name;
private Department derpartment;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Department getDerpartment() {
return derpartment;
}
public void setDerpartment(Department derpartment) {
this.derpartment = derpartment;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "id="+this.id+" name="+this.name;
}
}
package vo.util.bean;
import java.util.Map;
/**
*
* @author Administrator
*
*/
public class Department {
private int id;
private String name;
private Map<String,Employee> ems;
public Map<String, Employee> getEms() {
return ems;
}
public void setEms(Map<String, Employee> ems) {
this.ems = ems;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Map
private Map<String,Employee> ems;
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="vo.util.bean">
<class name="Department">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<!-- -->
<!--
<set name="ems">
-->
<!-- -->
<!--
<key column="depaer_id"/>
-->
<!-- -->
<!--
<one-to-many class="Employee" />
</set>
-->
<map name="ems">
<key column="depaer_id"/>
<map-key type="string" column="name"/>
<one-to-many class="Employee"/>
</map>
</class>
</hibernate-mapping>
List map
<map-key Map
type string column ?
name
package vo.util.test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.Transaction;
import vo.util.HibernateUtil;
import vo.util.bean.Department;
import vo.util.bean.Employee;
public class OneToMany {
/**
* @param args
*/
public static void main(String[] args) {
add();
query(1);
}
static Department add(){
Session session = null;
Transaction tx = null;
try{
session =HibernateUtil.getSession();
tx = session.beginTransaction();
//… save,delete,update,get…
Department dpart=new Department();
dpart.setName(" ");
Employee em1=new Employee();
em1.setName(" ");
em1.setDerpartment(dpart);
Employee em2=new Employee();
em2.setName(" ");
em2.setDerpartment(dpart);
Map<String,Employee> ems=new HashMap<String, Employee>();
ems.put(em1.getName(), em1);
ems.put(em2.getName(), em2);
dpart.setEms(ems);
session.save(dpart);
session.save(em1);
session.save(em2);
tx.commit();
return dpart;
}finally{
if(session != null)session.close();
}
}
static Department query(int id){
Session session=null;
try{
session=HibernateUtil.getSession();
Department d=(Department)session.get(Department.class, id);
System.out.println(d.getEms());
return d;
}finally{
if(session != null)session.close();
}
}
}
:
end !
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
React Native Mapbox(v10) 설치이 글에서는 React Native에서 지도를 통합하기 위한 도구로 Mapbox(v10)를 사용하는 기본 사항에 대해 알아봅니다. 나는 iOS와 Android 모두에서 완벽하게 작동하는 mapbox를 선호합니다. "...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.