Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

custom query on findOne method

$
0
0
Hi,

I am trying to define custom query for fetching object by id , bit it seem like it doesn't have effect when I define query on findOne() method in my repository interface (which extends CrudRepository)

I tried this:

Code:

@Query("SELECT p FROM Place p LEFT JOIN FETCH p.reviews WHERE p.id = ?1 ")
public Place findOne(Integer id);

bit it doesn't work, I get Place object with uninitialized child collection

If I define it on new method called findById and use same query on it, then it works.

Code:

@Query("SELECT p FROM Place p LEFT JOIN FETCH p.reviews WHERE p.id = ?1 ")
public Place findById(Integer id);

Can somebody clarify this for me... Is defining custom query on existing CrudRepository methods not allowed or am I missing something?

Thanks

Viewing all articles
Browse latest Browse all 297

Trending Articles