Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with FetchType.EAGER

Nghiem Nguyen
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I couldn't remove the entity instance in the child entity if the father entity had "fetch = FetchType.EAGER" before the Collection of child.

In father Entity:
@Table(name = "Phuong")
public class Phuong implements {
private String maphuong;
private String tenphuong;
private Collection<Khom> khoms;

public String getMaphuong() {
return maphuong;

public void setMaphuong(String maphuong) {
this.maphuong = maphuong;

public String getTenphuong() {
return tenphuong;

public void setTenphuong(String tenphuong) {
this.tenphuong = tenphuong;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,
public Collection<Khom> getKhoms() {
return khoms;

public void setKhoms(Collection<Khom> khoms) {
this.khoms = khoms;

In child Entity:
@Table(name = "Khom")
public class Khom implements {
private String makhom;
private String tenkhom;
private Phuong phuong;

public String getMakhom() {
return makhom;

public void setMakhom(String makhom) {
this.makhom = makhom;

public String getTenkhom() {
return tenkhom;

public void setTenkhom(String tenkhom) {
this.tenkhom = tenkhom;

@JoinColumn(name = "maphuong")
public Phuong getPhuong() {
return phuong;

public void setPhuong(Phuong phuong) {
this.phuong = phuong;

and In session Bean:
public void deleteKhom(String makhom){
khom = manager.find(Khom.class, makhom);
if(khom != null){
System.out.println("Removed Khom!");
System.out.println("Cannot find!");

Please Help me.
Thanks and sorry for my poor English.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic