Hi
I'm working with ejb 3.0 (jboss 4.0.3 rc2).
I have two classess:
Code:
@Entity
@Table(name="parents")
public class Parent implements Serializable {
private Integer idparent;
private String name;
private List<Child> children;
@Id(generate=GeneratorType.AUTO)
@Column(name="idparent")
public Integer getIdparent() {
return idparent;
}
public void setIdparent(Integer idparent) {
this.idparent = idparent;
}
@Column(name="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
public List<Child> getChildren() {
return children;
}
public void setChildren(List<Child> children) {
this.children = children;
}
}
Code:
@Entity
@Table(name="children")
public class Child implements Serializable {
private Integer idchild;
private String name;
private Parent parent;
@Id(generate=GeneratorType.AUTO)
@Column(name="idchild")
public Integer getIdchild() {
return idchild;
}
public void setIdchild(Integer idchild) {
this.idchild = idchild;
}
@Column(name="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ManyToOne
@JoinColumn(name="parent")
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}
I have stateless session bean which contains methods:Code:
public void updateParent(Parent p) {
em.merge(p); // entity manager
}
public List<Parent> getParents() {
return em.createQuery("from Parent p").getResultList();
}
in my client application there is something like this:Code:
Context context = new InitialContext();
Information inf = (Information)context.lookup(Information.class.getName());
Parent p = inf.getParents().iterator().next();
Child c = p.getChildren().iterator().next();
p.getChildren().remove(c);
c.setParent(null);
inf.updateParent(p);
In my opinion it should be OK, but this code doesn't delete anything in DB.
Adding new objects works good.
I was trying cascade (ALL and ORPHAN-DELETE) but i had the same problem.
What should I fix? How to delete object from collection?
Sorry for my english!!