Results 1 to 3 of 3

Thread: spring data jpa how implement interface query method in dao interface

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    Default spring data jpa how implement interface query method in dao interface

    hi,all,
    Code:
    @Query("from Staff where cardNo = :cardNo")
        public Staff findByCardNo(@Param("cardNo") String cardNo);
    but when I want to implement search method by a search criteria,how I to write the @Query("").I want to implement interface query methods in dao interface.
    thanks for help.

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

    Default

    I suggest a read of the spring-data-jpa reference guide... If you use @Query spring-data will generate the query for you if you want your own implementation don't use @Query but provide your own implementation (all that is explained in the reference guide).
    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

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Default

    Quote Originally Posted by Marten Deinum View Post
    I suggest a read of the spring-data-jpa reference guide... If you use @Query spring-data will generate the query for you if you want your own implementation don't use @Query but provide your own implementation (all that is explained in the reference guide).
    thanks a lot!
    like follows:
    class Depart{
    private int id;
    }
    class Staff{
    @ManyToMany()
    private List<Department> departments;
    }

    in daoImpl package:
    class StaffDaoImpl implements StaffDao{
    public List<Staff> findByDepartment(Long departmentId){
    Query query=em.createQuery("select staff from Staff staff left join fetch staff.departments d where d.id = :departmentId");
    query.setParameters("departmentId",departmentId);
    return query.getResultList();

    and now I want to use CriteriaBuilder implement "left join fetch staff.departments d where d.id = :departmentId",

    please help,thanks!

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
  •