Announcement Announcement Module
Collapse
No announcement yet.
custom query on findOne method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • custom query on findOne method

    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
Working...
X