java - How do I get a specific child entity from the parent agg in JPA where there could be many children -


i have 2 part question:

  1. i have root agg has children entities , there large number of them. looking efficient way specific one. right way load them in memory , through them. want them index out of db. there way through class directly without having load children entities?

  2. in trying around q1 made repository method it, apparently didn't name correctly spring automated generation. i'm using jpa/spring , have following repository:

    public interface foobarrepository extends crudrepository<foobar, long>{    someentitythatisachildentityoftherootaggfoobar finditembyfoobarandotheritem(foobar foobar, otheritem otheritem); } 

the problem doesn't work, spring throws exception stating can't property called foobar

factorybean threw exception on object creation; nested exception org.springframework.data.mapping.propertyreferenceexception: no property order found type com.bla.foobar.foobar 

i've tried using 'this' , 'id' , hoping worked, neither of them worked either.

i tried use jpql it, doesn't work either because child entity doesn't have knowledge of it's parent, although child entity table contain fk parent.

try native query, like:

public child findchildbyindex(parent parent, int index) {         return (child) em.createnativequery("select * childs parent_id = ?" , child.class)                 .setparameter(0, parent.getid())                 .setfirstresult(index)                 .setmaxresults(1)                 .getresultlist().get(0);     } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -