2 Replies Latest reply on Aug 25, 2009 10:31 PM by Jason Burns

    Seam-gen generated EntityQueries not respecting RESTRICTIONS

    Jason Burns Newbie

      Hello Seam community.  First let me say that if this is not a seam question/problem but more of a hibernate one, please let me know and I will post the question over there.


      So a simplified version of my scenario (I'll remove all the columns but one, etc...  ) -  I used seam-gen generate to initially create the structure of my project.  Let's say that that gave me a Users entity such:


      @Entity
      @Table(name = "users", uniqueConstraints = @UniqueConstraint(columnNames = "user_name"))
      public class Users implements java.io.Serializable {
      
           private Integer userId;
           private String userName;
      <snip>
      



      and a UsersList EntityQuery such:


      @Name("usersList")
      public class UsersList extends EntityQuery<Users> {
      
           private static final String EJBQL = "select users from Users users";
      
           private static final String[] RESTRICTIONS = {"lower(users.userName) like lower(concat(#{usersList.users.userName},'%'))",};
      
           private Users users = new Users();
      <snip>
      



      I now populate my DB with 10 users and run this code:


      UsersList ul = new UsersList();
      ul.getUsers().setUserName("John");
      List<Users> allResults = ul.getResultList();
      



      Now since the Javadoc for getResultList says it will update the restriction values, I expect this query to return all users that start with John.  This is what I see in the logs though:


      21:41:33,320 INFO  [STDOUT] Hibernate:
          select
              users0_.user_id as user1_89_,
              users0_.user_name as user2_89_
          from
              db.users users0_ limit ?
      



      First, I am confused why I don't see the where clause in the resulting hibernate call.  Second, iterating over the returned result set indeed shows that all 10 users have been returned.


      I have tried several different tests such as setting the restriction operator to and (and even or just to see), marked the EntityManager using @PersistentContext, making the bean Stateful, using unleaded gas, etc...


      I'm hoping someone can see it's just a piece of code I've left out or don't understand how to use from seam-gen's resulting structure.


      Any help is greatly appreciated.  Thanks!