Announcement Announcement Module
Collapse
No announcement yet.
spring data jpa how implement interface query method in dao interface Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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).

    Comment


    • #3
      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!

      Comment

      Working...
      X