1 Reply Latest reply on Apr 2, 2007 4:19 PM by Alex Savitsky

    Problem:

    Alex Savitsky Novice

      The environment is Tomcat 5.5.20 + Hibernate EM 3.3 + Seam 1.2.0 + Microcontainer. I'm trying to build a simple clickable list with editing, everything works fine (querying, updating), except when adding a new record:

      UserBean.java

      @Name ("userBean")
      @Scope (ScopeType.CONVERSATION)
      public class UserBean extends EntityController implements Serializable {
       @DataModelSelection
       @Out (required = false)
       private User selectedUser;
       @DataModel
       private List<User> users;
      
       public void addUser() {
       selectedUser = new User();
       }
       public void cancelEdit() {
       selectedUser = null;
       }
       @Factory ("users")
       @Begin (flushMode = FlushModeType.MANUAL)
       public void createRecords() {
       users = createQuery("SELECT u FROM User u").getResultList();
       }
       @Transactional (TransactionPropagationType.REQUIRED)
       public void saveUser() {
       persist(selectedUser);
       flush();
       addFacesMessage("User #{selectedUser.username} succesfully saved");
       createRecords();
       }
       public void selectUser() {
       }
      }
      


      users.xhtml (I'm using Facelets):
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
       xmlns:s="http://jboss.com/products/seam/taglib">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Manage Users</title>
      </head>
      <body>
      <h:form>
       <h:dataTable id="table" var="user" value="#{users}">
       <f:facet name="footer">
       <h:commandButton action="#{userBean.addUser}" value="Add New" />
       </f:facet>
       <h:column>
       <f:facet name="header">
       <h:outputText value="ID" />
       </f:facet>
       <h:commandLink value="#{user.id}" action="#{userBean.selectUser}" />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Username" />
       </f:facet>
       <h:outputText value="#{user.username}" />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Role" />
       </f:facet>
       <h:outputText value="#{user.role}" />
       </h:column>
       </h:dataTable>
       <h:panelGrid columns="2" rendered="#{not empty selectedUser}">
       <f:facet name="header">
       <h:messages />
       </f:facet>
       <f:facet name="footer">
       <h:panelGroup>
       <h:commandButton action="#{userBean.saveUser}" value="Save" />
       <h:commandButton action="#{userBean.cancelEdit}" immediate="true"
       value="Cancel" />
       </h:panelGroup>
       </f:facet>
       <h:outputLabel value="Username" for="username" />
       <h:inputText id="username" value="#{selectedUser.username}" required="true">
       <f:validateLength maximum="20" />
       </h:inputText>
       <h:outputLabel value="Password" for="password" rendered="#{selectedUser.new}" />
       <h:inputText id="password" value="#{selectedUser.password}" required="true"
       rendered="#{selectedUser.new}">
       <f:validateLength minimum="6" maximum="20" />
       </h:inputText>
       <h:outputLabel value="Role" for="role" />
       <h:selectOneMenu id="role" value="#{selectedUser.role}" required="true">
       <s:convertEnum />
       <s:enumItem enumValue="ROLE_USER" label="User" />
       <s:enumItem enumValue="ROLE_MGR" label="Manager" />
       <s:enumItem enumValue="ROLE_ADMIN" label="Administrator" />
       </h:selectOneMenu>
       </h:panelGrid>
      </h:form>
      </body>
      </html>
      


      User.java:
      @Entity
      @Table (name = "USERS")
      @SequenceGenerator (name = "SEQ_GEN", sequenceName = "SEQ_USER")
      public class User implements Serializable {
       public static enum Role {
       ROLE_ADMIN, ROLE_MGR, ROLE_USER
       }
      
       @Column (name = "CREATED_BY", nullable = false, updatable = false)
       private String createdBy = "ADMIN";
       @Temporal (TemporalType.TIMESTAMP)
       @Column (name = "CREATED_ON", nullable = false, updatable = false)
       private Date createdOn = new Date();
       @Id
       @GeneratedValue (strategy = GenerationType.AUTO, generator = "SEQ_GEN")
       private Long id;
       @Column (name = "MODIFIED_BY", nullable = false)
       private String modifiedBy = "ADMIN";
       @Temporal (TemporalType.TIMESTAMP)
       @Version
       @Column (name = "MODIFIED_ON", nullable = false)
       private Date modifiedOn = new Date();
       private String password;
       @Enumerated (EnumType.STRING)
       private Role role;
       private String username;
      
       public String getCreatedBy() {
       return createdBy;
       }
       public Date getCreatedOn() {
       return createdOn;
       }
       public Long getId() {
       return id;
       }
       public String getModifiedBy() {
       return modifiedBy;
       }
       public Date getModifiedOn() {
       return modifiedOn;
       }
       public String getPassword() {
       return password;
       }
       public Role getRole() {
       return role;
       }
       public String getUsername() {
       return username;
       }
       public boolean isNew() {
       return id == null;
       }
       public void setCreatedBy(String createdBy) {
       this.createdBy = createdBy;
       }
       public void setCreatedOn(Date createdOn) {
       this.createdOn = createdOn;
       }
       public void setId(Long id) {
       this.id = id;
       }
       public void setModifiedBy(String modifiedBy) {
       this.modifiedBy = modifiedBy;
       }
       public void setModifiedOn(Date modifiedOn) {
       this.modifiedOn = modifiedOn;
       }
       public void setPassword(String password) {
       this.password = password;
       }
       public void setRole(Role role) {
       this.role = role;
       }
       public void setUsername(String username) {
       this.username = username;
       }
      }
      


      persistence.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
       <persistence-unit name="visitsDatabase" transaction-type="JTA">
       <jta-data-source>java:comp/env/DataSource</jta-data-source>
       <properties>
       <property name="hibernate.show_sql" value="true" />
       <property name="hibernate.jdbc.batch_size" value="0" />
       <property name="hibernate.transaction.manager_lookup_class"
       value="org.hibernate.transaction.JBossTransactionManagerLookup" />
       </properties>
       </persistence-unit>
      </persistence>
      


      components.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://jboss.com/products/seam/security"
       xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd
       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.2.xsd
       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd">
       <core:init debug="true" />
       <core:manager conversation-timeout="120000"
       concurrent-request-timeout="500" />
       <core:entity-manager-factory name="visitsDatabase" />
       <core:managed-persistence-context name="entityManager" auto-create="true"
       entity-manager-factory="#{visitsDatabase}" />
       <core:microcontainer installed="true" />
       <security:identity authenticate-method="#{authenticator.authenticate}" />
      </components>
      


      jboss-beans.xml and jndi.properties have been copied from the Seam-JPA examples (Seam 1.2.0 distribution)

      And here's the stack trace I'm getting:
      ERROR [org.jboss.seam.web.ExceptionFilter] - uncaught exception
      javax.servlet.ServletException: Error calling action method of component with id _id2:_id33
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:154)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Thread.java:595)
      ERROR [org.jboss.seam.web.ExceptionFilter] - exception root cause
      javax.faces.FacesException: Error calling action method of component with id _id2:_id33
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
       at javax.faces.component.UICommand.broadcast(UICommand.java:109)
       at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
       at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
       at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
       at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.faces.el.EvaluationException: /users.xhtml @42,67 action="#{userBean.saveUser}": javax.persistence.TransactionRequiredException: no transaction is in progress
       at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
       ... 31 more
      Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
       at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:294)
       at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:81)
       at org.jboss.seam.framework.EntityController.flush(EntityController.java:52)
       at test.UserBean.saveUser(UserBean.java:41)
       at test.UserBean$$FastClassByCGLIB$$48b4ac17.invoke(<generated>)
       at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
       at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:37)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:34)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:63)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.TransactionInterceptor$1.work(TransactionInterceptor.java:32)
       at org.jboss.seam.util.Work.workInTransaction(Work.java:37)
       at org.jboss.seam.interceptors.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
       at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:154)
       at org.jboss.seam.intercept.JavaBeanInterceptor.intercept(JavaBeanInterceptor.java:89)
       at test.UserBean$$EnhancerByCGLIB$$ca960d22.saveUser(<generated>)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at com.sun.el.parser.AstValue.invoke(AstValue.java:130)
       at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
       at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
       ... 32 more


      Has anyone been encountering similar problems before? Am I using the beans correctly?

      Thanks,

      Alex