I am currently using spring-data-jpa in a legacy environment and a native jdbc / sql approach is needed to accomplish a number of operations (selects, updates, etc.).
Whenever I can, I use @Query annotation together with entity related repositories, keeping entities clean of process logic. But if I need to create a native query I need to put it into a jpa @NamedNativeQuery annotation into the entity, or to write it down into orm.xml.
IMHO, I think that developing a @NativeQuery annotation, that acts like the @Query one and accepts native sql statements, can improve the separation between the model and the persistence logic, keeping this where it really belongs (into the repository)
That's a great suggestion. Nevertheless I think we rather might end up with a plain native flag on the already existing @Query annotation all the other infrastructure support (potentially providing a custom query to be used for pagination etc.) should be reused and the flip switch between native and JPQL queries essentially boil down to a different method call on the EntityManager
Fixed, should be available in tonights snapshot. Note, that we don't support pagination and dynamic sorting on query methods using native queries as we'd have to manipulate the manually defined query which we cannot do reliably
Francesco Poli opened DATAJPA-117 and commented
I am currently using spring-data-jpa in a legacy environment and a native jdbc / sql approach is needed to accomplish a number of operations (selects, updates, etc.).
Whenever I can, I use
@Query
annotation together with entity related repositories, keeping entities clean of process logic. But if I need to create a native query I need to put it into a jpa@NamedNativeQuery
annotation into the entity, or to write it down intoorm.xml
.IMHO, I think that developing a
@NativeQuery
annotation, that acts like the@Query
one and accepts native sql statements, can improve the separation between the model and the persistence logic, keeping this where it really belongs (into the repository)Attachments:
Referenced from: commits c134e10
1 votes, 0 watchers
The text was updated successfully, but these errors were encountered: