Results 1 to 2 of 2

Thread: findbyExample() problem

  1. #1
    Join Date
    Jun 2008
    Posts
    6

    Default findbyExample() problem

    I am new to Spring and Hibernate and I have a problem mentioned as under...


    I have a table

    USER_MENU_RIGHTS
    [ id(PK),userid(FK),menuid(FK),accessibility(Varchar ) ]

    Data in the table as somewhat as follows...

    ID USER_ID MENU_ID ACCESSIBILITY

    24 18 3 false
    25 18 4 false
    26 18 5 false
    27 18 6 false
    30 19 2 false
    29 19 1 false
    32 19 4 false
    35 19 7 false


    In a java Class (Assembler ) I am using the following method which invokes findByExample() of USER_MENU_RIGHTS DAO.

    Code:
    public List loadUserRights(String userId)
    {
    		try{
    			Users user = userService.findById(new Long(userId));
    			UserRights userRights = new UserRights();
    			userRights.setUsers(user);
    			List userList = userRightsService.findByExample(userRights);
    			return userList;
    		}catch(Exception e){}
    		return null;
     }
    Actually I want to get a list of records WHERE USER_ID = some user id like 18... but it returns all the records of the table ... and the hibernate generated sql query is a little weired ...

    SELECT this_.ID AS ID4_0_, this_.MENU_ID AS MENU2_4_0_, this_.USER_ID AS USER3_4_0_, this_.ACCESSIBILITY AS ACCESSIB4_4_0_
    FROM KU.USER_MENU_RIGHTS this_ WHERE (1=1)

    Please help...

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Read the hibernate reference guide. When querying with a example it doesn't use the relations it only uses the basic properties of UserRights.

    I also suggest that you learn how to use the hibernate query language, because it can simply be achieved with a HQL (or using Criteria).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •