TransactionRequiredException with the jpa idm quick start
fer.marino Nov 13, 2013 2:05 PMIt seemed right to me open a new discussion for my own problem rather than abusing of the other one so here we are.
I'm running the demo in the subject on jboss as 7.1 + richfaces. Basically I did not made any major modifications, I'm still using the H2 database provided by the server, but not in memory. I'm also having hibernate.hbm2ddl.auto set to validate, to not delete and recreate the db every time. I've used the startup script just once to create the db, and then deleted.
All seems to works fine, so I've started to implements some view for the CRUD operations on the basic idm model provided. Here some code:
@SessionScoped @ManagedBean public class UserManager { @Inject private PartitionManager partitionManager; .... public void saveUser() { IdentityManager im = partitionManager.createIdentityManager(); im.update(editUser); if(password != null && !password.isEmpty() && confirmPassword != null && !confirmPassword.isEmpty()) if(password.equals(confirmPassword)) im.updateCredential(editUser, new Password(password)); else FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Password must match")); log.log(Level.INFO, "User "+editUser.getLoginName()+ " updated succesfully"); }
The im.update fail:
PLIDM000604: Could not update AttributedType
Caused by: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
I'm investigating this problem for two days. The entitymanager is correctly created and provided by the producer method, and with that it let me authenticate successfully. The em injected by the context is an instance of TransactionScopedEntityManager, so it should be fine. Calling em.getTransaction() fail with this java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction(), and this is also should be correct (getTransaction is used only for resource local data sources, isn't it?)
What I'm I doing wrong? In the startup script all seems to be working fine, why here it does not??
In the documentation it is said that IdentityManager is a requested scoped bean, while the partition manager is application scoped. Assuming that this scope is the same as jsf managed beans, I've injected the partition manager in my sessionscoped bean, but I've seen that injecting directly the identity manager works. I'm not grasping something here...