[jboss-user] [JBoss Seam] - best practice question: SMPC, @OneToOne and <h:selectOneMenu
hstang
do-not-reply at jboss.com
Fri Dec 22 12:50:01 EST 2006
I am encountering PersistenceException in designing a web form that results from using Seam-managed persistence context(SMPC) + @OneToOne and <h:selectOneMenu>. I am trying to use the entity as a pure JSF backing bean. The problem is modifying the department's ID, which is still managed by SMPC.
Does anyone know a clever design/solution to use @OneToOne + <h:selectOneMenu> ? The examples in Seam1.1GA do not appear to have this use case covered. The relevant codes are posted below. Thanks.
| Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=null:1166713106023/32, BranchQual=null:1166713106023, localId=0:32], status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.PersistenceException: org.hibernate.HibernateException: identifier of an instance of Department was altered from 1 to 2)
|
Employee.java
--
| @Name("employee")
| @Entity
| public class Employee {
|
| @Id
| @GeneratedValue
| private Long id;
|
| @OneToOne
| @JoinColumn(name = "departmentId")
| private Department department;
|
| // getters and setters
| }
Department.java
--
@Name("department")
| @Entity
| public class Department {
|
| @Id
| @GeneratedValue
| private Long id;
|
| private String name;
|
| // getters and setters
| }
UserView.java
--
@Name("userView")
| public class UserView {
| @In
| private EntityManager em;
|
| @Factory("departmentList")
| public List<SelectItem> initDepartmentList() {
| // use em; to return an instance of List<SelectItem>
| }
| }
|
user.xhtml
--
anonymous wrote :
| <h:selectOneMenu id="user.department" value="#{employee.department.id}">
| <f:convertNumber/>
| <f:selectItems value="#{departmentList}"/>
| </h:selectOneMenu>
| <h:commandButton value="Update" action="update"/>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3995922#3995922
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3995922
More information about the jboss-user
mailing list