In my web applicaton I use OpenJPA on Apache Tomcat (TomEE)/7.0.37 server.
my entity User.class:
@Entity
@Table(name = "USER")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Basic(optional = false)
@Column(name = "id_user")
private Integer idUser;
@Size(max = 8)
@Column(name = "login")
private String login;
@Size(max = 128)
@Column(name = "password")
private String password;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "user")
private Lecturer lecturer;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "user")
private Student student;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<UserHasRoles> userHasRolesList;
//constructors, getters, setters
}
when i create new user:
public void addUser(String log, String pass) {
User user = new User(); //utworzenie użytkownika i dodanie do bazy
user.setLogin(log);
user.setPassword(pass);
em.persist(user);
}
i get exception:
javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization
Caused by:
org.apache.geronimo.transaction.manager.SetRollbackOnlyException - setRollbackOnly() called. See stacktrace for origin
at org.apache.geronimo.transaction.manager.TransactionImpl.setRollbackOnly(TransactionImpl.java:126)
I try to change generation id strategy, but it dosen't help. What is wrong?
stack trace from my application:
org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:108)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:68)
at javax.faces.component.UICommand.broadcast(UICommand.java:120)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at filters.NoCacheFilter.doFilter(NoCacheFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization
at org.apache.el.parser.AstValue.invoke(AstValue.java:291)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
... 30 more
Caused by: javax.ejb.EJBTransactionRolledbackException: Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:345)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:283)
at model.logic.UserService$LocalBeanProxy.addUser(model/logic/UserService.java)
at model.backingbeans.RegisterBacking.register(RegisterBacking.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
... 32 more
Caused by: javax.transaction.RollbackException: Unable to commit: transaction marked for rollback
at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:272)
at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)
at org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:328)
at org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
at org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:76)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:259)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:191)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:246)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:241)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:83)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:279)
... 39 more
Caused by: org.apache.geronimo.transaction.manager.SetRollbackOnlyException: setRollbackOnly() called. See stacktrace for origin
at org.apache.geronimo.transaction.manager.TransactionImpl.setRollbackOnly(TransactionImpl.java:126)
at org.apache.geronimo.transaction.manager.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:243)
at org.apache.openejb.core.TransactionSynchronizationRegistryWrapper.setRollbackOnly(TransactionSynchronizationRegistryWrapper.java:71)
at org.apache.openjpa.ee.RegistryManagedRuntime$TransactionManagerRegistryFacade.setRollbackOnly(RegistryManagedRuntime.java:128)
at org.apache.openjpa.ee.RegistryManagedRuntime.setRollbackOnly(RegistryManagedRuntime.java:74)
at org.apache.openjpa.ee.AutomaticManagedRuntime.setRollbackOnly(AutomaticManagedRuntime.java:274)
at org.apache.openjpa.kernel.BrokerImpl.setRollbackOnlyInternal(BrokerImpl.java:1660)
at org.apache.openjpa.kernel.BrokerImpl.setRollbackOnly(BrokerImpl.java:1640)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1847)
at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:616)
at org.apache.openjpa.kernel.StateManagerImpl.assignField(StateManagerImpl.java:703)
at org.apache.openjpa.kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java:1615)
at org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1598)
at model.entity.User.pcGetidUser(User.java)
at model.entity.User.toString(User.java:137)
at java.text.MessageFormat.subformat(MessageFormat.java:1271)
at java.text.MessageFormat.format(MessageFormat.java:860)
at java.text.Format.format(Format.java:157)
at java.text.MessageFormat.format(MessageFormat.java:836)
at org.apache.openjpa.lib.util.Localizer$Message.getMessage(Localizer.java:282)
at org.apache.openjpa.util.OpenJPAException.<init>(OpenJPAException.java:64)
at org.apache.openjpa.util.UserException.<init>(UserException.java:47)
at org.apache.openjpa.util.InvalidStateException.<init>(InvalidStateException.java:34)
at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:567)
at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:505)
at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2982)
at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1054)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2112)
at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2072)
at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1990)
at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527)
at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:512)
at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:413)
at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:262)
... 49 more
Ok, i find my fault:
I got this exception because I had password field in database for 64 character (CHAR(64)) and I tried to write there 128 character String. Changing table in database resolved my problem.
So, when you get this exception check if your @Entity class has same field (with same types) like your types in database table.
Thank you all for help. I'm sorry for the trouble and confusion.