首页  >  文章  >  后端开发  >  hibernate单实体的级联查询

hibernate单实体的级联查询

巴扎黑
巴扎黑原创
2016-12-20 14:20:271305浏览

其实单实体的一对多和多对一和2个实体的用法是一样的,现在以user为例:

 

java代码:

 

package com.test.bean;

import java.util.Set;

public class User
{
 private Integer id;
 private String firstname;
 private String lastname;
 private Integer parentID;
 private int age;
 private Set childrens;
 private User user;

 

 public Set getChildrens() {
  return childrens;
 }

 public void setChildrens(Set childrens) {
  this.childrens = childrens;
 }

 public User getUser() {
  return user;
 }

 public void setUser(User user) {
  this.user = user;
 }

 public Integer getId()
 {
  return id;
 }

 public void setId(Integer id)
 {
  this.id = id;
 }

 public String getFirstname()
 {
  return firstname;
 }

 public void setFirstname(String firstname)
 {
  this.firstname = firstname;
 }

 public String getLastname()
 {
  return lastname;
 }

 public void setLastname(String lastname)
 {
  this.lastname = lastname;
 }

 public int getAge()
 {
  return age;
 }

 public void setAge(int age)
 {
  this.age = age;
 }

 public Integer getParentID() {
  return parentID;
 }

 public void setParentID(Integer parentID) {
  this.parentID = parentID;
 }

}


对应的hbm文件:


"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


 
  
   
  

   length="50">
  

   length="50">
  

   

   lazy="false" where=" age=4">
   
    
   

   
  

     
  
 


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn