• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with FetchType.EAGER

 
Nghiem Nguyen
Greenhorn
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:
@Entity
@Table(name = "Phuong")
public class Phuong implements java.io.Serializable {
private String maphuong;
private String tenphuong;
private Collection<Khom> khoms;

@Id
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,
mappedBy="phuong")
public Collection<Khom> getKhoms() {
return khoms;
}

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


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

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

@ManyToOne
@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){
manager.remove(khom);
System.out.println("Removed Khom!");
}
else{
System.out.println("Cannot find!");
}
}

Please Help me.
Thanks and sorry for my poor English.
Rock.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!