2 Replies Latest reply on Mar 13, 2012 11:44 AM by cyberanto

    accessing transient properties in EntityQuery Restrictions

    cyberanto Newbie

      Seam 2.2.2, JBoss 5.1;


      When I try to access a transient property in the EL of a Restriction in EntityQuery, I get:


      java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: ...

           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)

           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)




      when I call getResultList() - the same EL works perfectly fine in a page. I assume I am doing something wrong, or are there differences in the EL resolvers being called in the two use scenarios? Before I start adding my own EL Resolver, I am fishing for feedback - anyone else who ran into this and resolved it?







      public class TransientPropertyELDemo {

           private String transientProperty="transient";


           // ... other properties, persistent



           public String getTransientProperty() {

                return transientProperty;


           // .... setter




      <h:inputText id="transient" value="#{transientDemo.transientProperty}" /> <!-- works as expected -->



      public class TransientPropertyQuery extends EntityQuery<TransientPropertyELDemo> {


                private static final String EJBQL = "select demo from TransientPropertyELDemo demo";


                private static final String[] RESTRICTIONS = {

                               "lower(demo.persistentProperty) like lower(concat(#{transientDemo.persistentProperty},'%'))",

                               "lower(demo.transientProperty) like lower(concat(#{transientDemo.transientProperty},'%'))",};


                public TransientPropertyQuery() {







        • 1. Re: accessing transient properties in EntityQuery Restrictions
          gebuh Newbie

          I don't see how you can do that using entityQuery restrictions at all.  The restrictions are for querying the db table backing the entity.  The transient field doesn't exist in that table.  When you call getResultList() you're returning the entity, the transient field does exist in the entity.

          1 of 1 people found this helpful
          • 2. Re: accessing transient properties in EntityQuery Restrictions
            cyberanto Newbie

            After spending a little time looking into this, I realized that I was wrong about the EL not being resolved - it resolves just fine. So tranient properties *can* be used in the EL part of the Restrictions.


            The problem is with demo.transientProperty (the left-hand-side of the comparison), which cannot be translated into SQL (thanks Beth). It could only be resolved *after* the SQL resultlist is returned and Entities are being created. While this would be nice from a simplicity/architectural point of view, it creates potentially very inefficient SQL queries and large result sets having to be retuned before the logic can be executed. So Hibernate avoids that, understandably so.


            My goal was to avoid having BL in the query, and it all located in a non-anemic entity. Guess this is an OO/Relational Impedance issue that cannot be easily resolved.


            Off to rewriting the query to include the necessary logic.