1 Reply Latest reply on Sep 10, 2007 9:20 AM by Peter Bugiel

    Query over two tables causes 'Transaction is not active...'

    Peter Bugiel Newbie

      Hi,

      performing the following query causes the error/exception as displayed bellow:

      SELECT c, cd FROM Category c, CategoryDetails cd WHERE c.categoryID != 1 AND c.categoryID = cd.category.categoryID AND cd.locale = 'de' ORDER BY cd.name


      10:47:54,984 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
      10:47:54,984 ERROR [JDBCExceptionReporter] Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f574d9c:474:46e503c2:44 status: ActionStatus.ABORT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f574d9c:474:46e503c2:44 status: ActionStatus.ABORT_ONLY >)
      10:47:55,000 ERROR [STDERR] Sep 10, 2007 10:47:54 AM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/home.xhtml]
      javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connection
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:204)
       at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:100)
       at $Proxy135.init(Unknown Source)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
       at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:72)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
       at org.jboss.seam.interceptors.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:40)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:31)
       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.ClientSideInterceptor.invoke(ClientSideInterceptor.java:50)
       at org.javassist.tmp.java.lang.Object_$$_javassist_2.init(Object_$$_javassist_2.java)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
       at org.jboss.seam.Component.callComponentMethod(Component.java:1834)
       at org.jboss.seam.Component.getInstanceFromFactory(Component.java:1696)
       at org.jboss.seam.Component.getInstance(Component.java:1633)
       at org.jboss.seam.Component.getInstance(Component.java:1610)
       at org.jboss.seam.Component.getInstance(Component.java:1604)
       at org.jboss.seam.jsf.SeamELResolver.getValue(SeamELResolver.java:49)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
       at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
       at org.apache.el.parser.AstValue.getValue(AstValue.java:86)
       at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at javax.faces.component.UIData.getValue(UIData.java:582)
       at org.richfaces.component.UITree.createDataModel(UITree.java:497)
       at org.richfaces.component.UITree.createDataModel(UITree.java:520)
       at org.ajax4jsf.ajax.repeat.UIDataAdaptor.getExtendedDataModel(UIDataAdaptor.java:522)
       at org.ajax4jsf.ajax.repeat.UIDataAdaptor.setRowKey(UIDataAdaptor.java:302)
       at org.ajax4jsf.ajax.repeat.UIDataAdaptor.setRowKey(UIDataAdaptor.java:287)
       at org.richfaces.renderkit.TreeRendererBase.writeContent(TreeRendererBase.java:393)
       at org.richfaces.renderkit.TreeRendererBase.encodeChildren(TreeRendererBase.java:284)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
       at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:571)
       at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:233)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
       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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       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.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:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.
      10:47:55,000 ERROR [STDERR] invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Unknown Source)
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
       at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
       at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
       at com.xcitesoft.wsp.business.session.CategoryTreeAction.init(CategoryTreeAction.java:79)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
       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.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.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
       ... 105 more
      Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
       at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
       at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
       at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
       at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
       at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
       at org.hibernate.loader.Loader.doQuery(Loader.java:673)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
       at org.hibernate.loader.Loader.doList(Loader.java:2220)
       at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
       at org.hibernate.loader.Loader.list(Loader.java:2099)
       at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
       at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
       at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
       at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
       at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
       at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
       ... 134 more


      Plain queries as "SELECT c FROM Category c" run trouble-free.

      My setup:
      JBoss AS 4.2.1
      Seam 1.2.1
      MySQL 5.0 DBMS
      mysql-connector-java-5.0.7-bin.jar

      Thanks for any help!

        • 1. Re: Query over two tables causes 'Transaction is not active.
          Peter Bugiel Newbie

          Maybe some more snippets of my code should be beneficial.

          The DB schema:

          /* category */
          create table category
          (
           categoryID int not null primary key auto_increment,
           image varchar(50)
          ) type = innodb;
          
          /* categorytree */
          create table categorytree
          (
           parentID int not null,
           childID int not null
          ) type = innodb;
          
          /* categorydetails */
          create table categorydetails
          (
           categorydetailsID int not null primary key auto_increment,
           categoryID int not null,
           locale varchar(10),
           name varchar(50),
           description mediumtext
          ) type = innodb;


          The appropriate entity beans:
          @Entity
          @Name("category")
          @Table(name="category")
          @NamedQueries({@NamedQuery(name="find_all_categories",query="SELECT c FROM Category c"),
           @NamedQuery(name="find_all_categories_but_root",query="SELECT c, cd " +
           "FROM Category c, CategoryDetails cd " +
           "WHERE c.categoryID != 1 " +
           "AND c.categoryID = cd.category.categoryID " +
           "AND cd.locale = 'de' " +
           "ORDER BY cd.name"),
           @NamedQuery(name="find_category_root",query="SELECT c FROM Category c WHERE c.categoryID = 1")})
          public class Category
          implements Serializable
          {
           private static final long serialVersionUID = 4195849772297525701L;
          
           private Integer categoryID;
           private String image;
           private Collection<CategoryDetails> categoryDetails;
           private Category parent;
           private Collection<Category> children;
          
           public Category()
           {
           super();
           }
          
           /**
           * @return the categoryID
           */
           @Id
           @GeneratedValue(strategy=GenerationType.AUTO)
           public Integer getCategoryID()
           {
           return categoryID;
           }
          
           /**
           * @param categoryID the categoryID to set
           */
           public void setCategoryID(Integer categoryID)
           {
           this.categoryID = categoryID;
           }
          
           /**
           * @return the image
           */
           public String getImage()
           {
           return image;
           }
          
           /**
           * @param image the image to set
           */
           public void setImage(String image)
           {
           this.image = image;
           }
          
           /**
           * @return the categoryDetails
           */
           @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="category")
           public Collection<CategoryDetails> getCategoryDetails()
           {
           return categoryDetails;
           }
          
           /**
           * @param categoryDetails the categoryDetails to set
           */
           public void setCategoryDetails(Collection<CategoryDetails> categoryDetails)
           {
           this.categoryDetails = categoryDetails;
           }
          
           /**
           * @return the parent
           */
           @ManyToOne
           @JoinTable(name="categorytree",
           joinColumns={@JoinColumn(name="childID")},
           inverseJoinColumns={@JoinColumn(name="parentID")})
           public Category getParent()
           {
           return parent;
           }
          
           /**
           * @param parent the parent to set
           */
           public void setParent(Category parent)
           {
           this.parent = parent;
           }
          
           /**
           * @return the children
           */
           @ManyToMany(cascade=CascadeType.ALL)
           @JoinTable(name="categorytree",
           joinColumns={@JoinColumn(name="parentID")},
           inverseJoinColumns={@JoinColumn(name="childID")})
           public Collection<Category> getChildren()
           {
           return children;
           }
          
           /**
           * @param children the children to set
           */
           public void setChildren(Collection<Category> children)
           {
           this.children = children;
           }
          }
          
          
          
          @Entity
          @Name("categorydetails")
          @Table(name="categorydetails")
          public class CategoryDetails
          implements Serializable
          {
           private static final long serialVersionUID = -8279365282184781250L;
          
           private Integer categoryDetailsID;
           private Category category;
           private String locale;
           private String name;
           private String description;
          
           public CategoryDetails()
           {
           super();
           }
          
           /**
           * @return the categoryDetailsID
           */
           @Id
           @GeneratedValue(strategy=GenerationType.AUTO)
           public Integer getCategoryDetailsID()
           {
           return categoryDetailsID;
           }
          
           /**
           * @param categoryDetailsID the categoryDetailsID to set
           */
           public void setCategoryDetailsID(Integer categoryDetailsID)
           {
           this.categoryDetailsID = categoryDetailsID;
           }
          
           /**
           * @return the category
           */
           @ManyToOne
           @JoinColumn(name="categoryID")
           public Category getCategory()
           {
           return category;
           }
          
           /**
           * @param category the category to set
           */
           public void setCategory(Category category)
           {
           this.category = category;
           }
          
           /**
           * @return the locale
           */
           public String getLocale()
           {
           return locale;
           }
          
           /**
           * @param locale the locale to set
           */
           public void setLocale(String locale)
           {
           this.locale = locale;
           }
          
           /**
           * @return the name
           */
           public String getName()
           {
           return name;
           }
          
           /**
           * @param name the name to set
           */
           public void setName(String name)
           {
           this.name = name;
           }
          
           /**
           * @return the description
           */
           public String getDescription()
           {
           return description;
           }
          
           /**
           * @param description the description to set
           */
           public void setDescription(String description)
           {
           this.description = description;
           }
          }