Get query from file in SPRING BOOT using @Query

后端 未结 3 966
借酒劲吻你
借酒劲吻你 2021-01-25 03:11

I have a proyect that use to load queries this:

@Query(value = SELECT_BY_USER_ID, nativeQuery = true)
Employee findByUserId(@Param(\"userId\") String userId);
         


        
3条回答
  •  长情又很酷
    2021-01-25 03:50

    Unfortunately, spring data doesn't seem to support direct properties reference withing @Query anno (like in @Value). Despite that and assuming you use spring-data-jpa and Hibernate it is possible to use an external .xml file to store your queries as named queries and refer to them by method name, or like

    @Query(nativeQuery = true, name="Repository1.query1")
    

    This is a nice article on this matter : JPA Queries in XML File and it describes how to place your .xml file elsewhere than the expected orm.xml

提交回复
热议问题