1 Reply Latest reply on Feb 4, 2009 3:38 PM by Robert B.

    Override getEJBQL with Parameters

    Robert B. Newbie
      Hi I am a real noob in seam and trying to use the generated List sessionobject.

      I like to make a Join between 2 Entities ( Element, Element Synonyms). Also i like to filter the Results with Parameters from a Form. (Elementname and Element NameChem)

      So what i am like to do is to search in Elements for this name  OR in Element_Synonyms

      With Restrictions i dont have a Idea how to make a OR  cause there i only can give one value Binding per Restriction and they will be Concat with an AND.

      I Tryed to Override the getResultList Methode with something like:
      getEntityManager().createQuery(EJBQL).setParameter("name", "#{ParameterElementList.parameterElement.name}").getResultList();

      This worked but every Row in the Database produced a Select statement.

      So i Tryed to Override now the getEBQL methode but i have no Idea how to get the Parameters into the EJBQL i tryed with #{...name} in the whenclause.

      My last try was this one:
      public class ParameterElementList extends EntityQuery<ParameterElement> {
           static private Log log2;
           private static final String EJBQL = "select parameterElement from ParameterElement parameterElement left join fetch parameterElement.parameterElementSynonyms pes";
           private static final String  whereClause = " WHERE " +
                     "(lower(parameterElement.name) like concat(lower(:name),'%') OR "+
                     " lower(pes.id.nameSynonym) like concat(lower(:name),'%'))" +
                     " AND " +
                     "(lower(parameterElement.nameChem) like concat(lower(:nameChem),'%') OR "+
                     " lower(pes.id.nameSynonym) like concat(lower(:nameChem),'%'))";
           private static final String[] RESTRICTIONS = {};

           private ParameterElement parameterElement = new ParameterElement();


              public ParameterElementList() {
                final List parameterUeber = new ArrayList();
                parameterUeber.add(this.parameterElement.getName() != null ? this.parameterElement.getName() : "");
                parameterUeber.add(this.parameterElement.getNameChem()!= null ? this.parameterElement.getNameChem() : "");

           public String getEjbql() {

                return EJBQL+whereClause;
           public List<ParameterElement> getResultList() {
                // TODO Auto-generated method stub
                return super.getResultList();

           public ParameterElement getParameterElement() {
                return parameterElement;

      Does somebody could help me with is issue?
        • 1. Re: Override getEJBQL with Parameters
          Robert B. Newbie

          I found a Workaround for this issue but i am not sure if this is a valid way.

          i made a private resultListCash and I overwrote the getResultList methode.

               public List<ParameterElement> getResultList() {
                    if (this.resultListCash == null || this.resultListCash.size()== 0){
                                this.resultListCash = getEntityManager().
                    return resultListCash;

          Am i right that for every Call a new Instance of the List object is Created and so the resultListCash is renewed?

          Does somebody has a better Idea?