Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Beans > Java Server Fac...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 1317 of 1372
Post > Topic >>

Java Server Faces and Java Persistence API - Newbie problem

by nax <naxat88@[EMAIL PROTECTED] > Aug 9, 2007 at 05:49 PM

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.
 




 2 Posts in Topic:
Java Server Faces and Java Persistence API - Newbie problem
nax <naxat88@[EMAIL PR  2007-08-09 17:49:33 
Re: Java Server Faces and Java Persistence API - Newbie problem
nax <naxat88@[EMAIL PR  2007-08-10 11:44:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:48:21 CDT 2008.