[jboss-user] [JBoss Seam] - Re: Basic Seam questions
lightbulb432
do-not-reply at jboss.com
Thu Dec 14 03:39:40 EST 2006
I have made a simple example below that doesn't seem to be working. It creates an entity (Person) over two independent JSF action methods:
@Stateful
| @Name("register")
| public class RegisterBean implements Register {
|
| @PersistenceContext(type=EXTENDED)
| private EntityManager em;
|
| @In(create=true) @Out
| private Person person;
|
| private String firstName;
| private String lastName;
|
| public String firstName() {
|
| person.setFirstName(getFirstName());
|
| em.persist(person);
|
| return "success";
|
| }
|
| public String lastName() {
|
| person.setLastName(getLastName());
|
| em.merge(person);
|
| return "success";
|
| }
|
| @Remove
| @Destroy
| public void destroy() {
|
| }
|
| }
I have a few questions on this example, but first, am I doing this correctly? Do I have the persist() and merge() in the correct places? Or should I remove the persist() and merge() and just have one persist() in lastName() - assuming lastName() is the second method to be called?
Is an EXTENDED persistence context correct here?
I'm getting an error in the second method, saying that "Exception during INVOKE_APPLICATION(5): javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: "
Here's the problem. When I call the firstName() method, followed by the lastName() method, the lastName() method seems to create a brand new Person. This Person gets a lastName, does not pick up the firstName from the previous method invocation, and triggers a PropertyValueException because of the validation annotation on the entity...whoa!
What am I doing wrong? Any help would be greatly appreciated. Thanks.
P.S. I don't call the destroy() method anywhere in the code at all. And, while I define destroy in the business interface, I don't define the annotations there...should I?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993733#3993733
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993733
More information about the jboss-user
mailing list