4 Replies Latest reply on Aug 21, 2008 12:15 AM by Siarhei Dudzin

    Warning and Transaction Failed on EntityQuery

    scott duke Novice

      I have a class called CodeList.java that I use to retrieve a listing when I perform a search. On my search CodeList.xhtml when I select both type and active, I receive on the top of the screen is Transaction failed. However, if I select only one of these options, it works just fine. In the log file I also see the following:

      21:58:02,415 WARN  [lifecycle] javax.el.ELException: /CodeList.xhtml @63,65 rendered="#{empty codeList.resultList}": Error reading 'resultList' on type com.ds.artwork.CodeList_$$_javassist_10


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      <ui:define name="body">
          <h:messages globalOnly="true" styleClass="message"/>
          <h:form id="cityStateZipSearch" styleClass="edit">
              <rich:simpleTogglePanel label="Code Search Parameters" switchType="ajax">
                      <s:decorate id="typeDecoration" template="layout/display.xhtml">
                      <ui:define name="label">Type</ui:define>               
                              <h:selectOneMenu value="#{codeList.code.type}" id="codeType" >
                                      <s:selectItems value="#{codeList.codeTypes}" var="_codeType" label="#{_codeType.value}" 
                                                                 noSelectionLabel="Please Select Type... "/>
                                      <s:convertEnum />
                  <s:decorate template="layout/display.xhtml">
                      <ui:define name="label">Code</ui:define>
                      <h:inputText id="code" value="#{codeList.code.code}"/>
                  <s:decorate template="layout/display.xhtml">
                      <ui:define name="label">Description</ui:define>
                      <h:inputText id="description" value="#{codeList.code.description}"/>
                  <s:decorate id="activeDecoration" template="layout/display.xhtml">
                      <ui:define name="label">Active</ui:define>               
                              <h:selectOneMenu id="active" 
                                   <f:selectItems value="#{codeList.booleanCodes}" />                                   
              <div class="actionButtons">
                  <h:commandButton id="search" value="Search" action="/CodeList.xhtml"/>
              <f:facet name="header">Code Search Results</f:facet>
              <div class="results" id="codeList">
                  <h:outputText value="No code exists" 
                             rendered="#{empty codeList.resultList}"/>
                  <rich:dataTable id="codeList" 
                            rendered="#{not empty codeList.resultList}">
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Type #{codeList.order=='type.value asc' ? messages.down : ( codeList.order=='type.value desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='type.value asc' ? 'type.value desc' : 'type.value asc'}"/>
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Code #{codeList.order=='code asc' ? messages.down : ( codeList.order=='code desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='code asc' ? 'code desc' : 'code asc'}"/>
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Description #{codeList.order=='description asc' ? messages.down : ( codeList.order=='description desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='description asc' ? 'description desc' : 'description asc'}"/>
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Available #{codeList.order=='active asc' ? messages.down : ( codeList.order=='active desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='active asc' ? 'active desc' : 'active asc'}"/>
                                  <f:facet name="header">Action</f:facet>
                                  <s:link view="/#{empty from ? 'Code' : from}.xhtml" 
                                      <f:param name="codeId" 
          <s:div styleClass="actionButtons" rendered="#{empty from}">
              <s:button view="/CodeEdit.xhtml"
                       value="Create Code">
                  <f:param name="codeId"/>


      package com.ds.artwork;
      import java.util.ArrayList;
      import java.util.Arrays;
      import java.util.List;
      import javax.faces.model.SelectItem;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityQuery;
      import com.ds.artwork.entity.Code;
      import com.ds.artwork.entity.Item;
      import com.ds.artwork.utils.CodeType;
      public class CodeList extends EntityQuery<Item> {
              private static final long serialVersionUID = 1008397397027179231L;
              // @In(required=false) @Out(required=false)
              // private String active = "";
              private static final String[] RESTRICTIONS = {
                              "code.type = #{codeList.code.type}",
                              "lower(code.code) like concat(lower(#{codeList.code.code}),'%')",
                              "lower(code.description) like concat(lower(#{codeList.code.description}),'%')", 
              private Code code = new Code();
              public String getEjbql() {
                      return "select code from Code code";
              public Integer getMaxResults() {
                      return 25;
              public Code getCode() {
                      return code;
              public List<String> getRestrictions() {
                      // return Arrays.asList(RESTRICTIONS);
                      //List<String> restrictions = Arrays.asList(RESTRICTIONS);
                      ArrayList<String> restrictions = new ArrayList<String>(0);
                      if (code.getStrActive() != null) {
                              restrictions.add("code.active = #{" + Boolean.valueOf(code.getStrActive()) + "}");
                      return restrictions;
              public String getOrder() {
                      if (super.getOrder() == null) {
                              setOrder("type asc");
                      return super.getOrder();
              public CodeType[] getCodeTypes() {
                      return CodeType.values();
              public List<Code> getBooleanCodes() {
                      // return
                      // this.getEntityManager().createNamedQuery("code.findCodesByType").setParameter("type",
                      // CodeType.BOOLEAN).getResultList();
                      List choices = new ArrayList();
                      choices.add(new SelectItem("", " "));
                      choices.add(new SelectItem("true", "True"));
                      choices.add(new SelectItem("false", "False"));
                      return choices;
              public List<Code> getEditionCodes() {
                      return this.getEntityManager().createNamedQuery("code.findCodesByType")
                                      .setParameter("type", CodeType.EDITION).getResultList();
              public List<Code> getMediumCodes() {
                      return this.getEntityManager().createNamedQuery("code.findCodesByType")
                                      .setParameter("type", CodeType.MEDIUM).getResultList();

      Does anyone know what the problem is?

        • 1. Re: Warning and Transaction Failed on EntityQuery
          scott duke Novice

          I need to clarify what I originally said.

          When I select both active and type, the query works, but I receive the transaction failed on the query screen and I also get the warning in the log file.

          When I select either active or type, the query works without the 2 messages appearing.

          I am using Seam-2.1.0-snapshot.

          • 2. Re: Warning and Transaction Failed on EntityQuery
            scott duke Novice

            It appears the problem is in the getRestrictions method and the adding of another restriction. Going from 3 restrictions to 4, causes the problem.

            So, let me back up and ask this. What is the proper way to handle a Boolean on a search? Initially, when you go to the search screen, the listing displays everything. If you use a checkbox, the selection is true or false. I want the user to be able to select based upon a selectOneMenu one of the following: nothing, true or false.

            I changed my Code.java adding:

                 public String getStrActive() {
                      if (active == null) {
                           strActive = null;
                      } else if (active.booleanValue()) {
                           strActive = "True";
                      } else {
                           strActive = "False";
                      return strActive;

            and added to the RESTRICTIONS in CodeList.java

            "code.strActive = #{codeList.code.strActive}",

            This is now selecting the data as I would like it. However, when I select the type and active, then search, the value on the active disappears.

            • 3. Re: Warning and Transaction Failed on EntityQuery
              scott duke Novice

              I decided to change the active field to an enum like the type field. It now works as I am wanting.