Hello,
I've got this simple Book-class, whose objects should be stored in a
database:
im****t java.io.Serializable;
im****t javax.persistence.Entity;
im****t javax.persistence.GeneratedValue;
im****t javax.persistence.Id;
im****t javax.persistence.NamedQuery;
@[EMAIL PROTECTED]
(name = "findAllBooks", query = "SELECT OBJECT(bk) from
Book bk")
public class Book implements Serializable {
private Long id;
private String author;
private String title;
private boolean available;
// [...]
@[EMAIL PROTECTED]
Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// [...]
}
I've written the following session bean to handle serialization of the
Book-objects:
im****t javax.annotation.Resource;
im****t javax.persistence.EntityManager;
im****t javax.persistence.PersistenceContext;
im****t javax.transaction.UserTransaction;
public class BookBean {
@[EMAIL PROTECTED]
(unitName="books")
private EntityManager em;
@[EMAIL PROTECTED]
UserTransaction utx;
private Book currentBook = new Book();
// [...]
public String submitBook() {
try {
utx.begin();
em.persist(currentBook);
utx.commit();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
currentBook = null;
return "submitBook";
}
// [...]
}
The submitBook()-method of the BookBean is called by a .jsp-File from
which the user can create a new Book-object, which is stored in the
currentBook-object. However, when the program reaches the utx.commit()-
statement the following Exception is thrown:
java.lang.IllegalStateException: During synchronization a new object
was found through a relation****p that was not marked cascade PERSIST.
at
oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork
$1.iterate(RepeatableWriteUnitOfWork.java:115)
[...]
Does anyone know why I get this strange exception although I haven't
used any relation****ps at all in my JSF-program?
Thanks for any help.