hibernate_1700_one2many_many2one_bi_crud(4)

还是那个例子


package com.bit.hibernate;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@Table(name="t_user")
public class User {

private int id;
private String name;
private Group group;

@Id
@GeneratedValue
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;
}

@ManyToOne(cascade={CascadeType.ALL},fetch=FetchType.LAZY) //加点东西
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}



}

这样的话你查多的一方   一那一方就不给你查出来了 因为你弄了个懒加载
只有当你用到了才帮你查出来

你可能感兴趣的:(Hibernate)