I'm trying to persist an object, after that i want to add 2 lists to that object and then update it (Since i can't persist the object with the lists).
All beign done inside a loop, the first iteration works just fine, from the second i get a EntityNotFoundException
saying that the ID wasn't found to do the update.
private Foo foo;
private FooDao dao;
for(int i = 0 ; i<10 ; i++){
foo = new Foo();
foo.setVar(i);
dao.save(foo);
generateLists(); //creates a new list every interaction
foo.setCatList(catList);
foo.setBarList(barList);
dao.update(foo);
}
If i remove the Lists and the update it works fine.
The object:
@Entity
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
private Integer id;
@Basic(optional = false)
@NotNull
private String var;
@OneToMany(cascade = CascadeType.ALL)
private List<Bar> barList;
@OneToMany(cascade = CascadeType.ALL)
private List<Cat> catList;
//Getters and Setters
}
The DAO methods:
public void save(Foo foo) {
this.manager.joinTransaction();
this.manager.persist(foo);
//this.manager.flush(); Tried this, but didn't work
}
public void update(Foo foo) {
this.manager.joinTransaction();
this.manager.merge(foo);
}
The error:
ERROR [org.jboss.as.ejb3] (EJB default - 1) javax.ejb.EJBTransactionRolledbackException: Unable to find foo with id 4
ERROR [org.jboss.as.ejb3.invocation] (EJB default - 1) JBAS014134: EJB Invocation failed on component FooDao for method public void FooDao.atualiza(Foo): javax.ejb.EJBTransactionRolledbackException: Unable to find Foo with id 4
ps: Using this generic approach to simplify, if needed i'll post my solution(or the mess that i call solution)