join more than one table in spring jparepository -
i trying fetch record doing join. new spring jparepository. understand there separate repository each entity(table) when implement need define entity , datatype of primary key.
could please suggest how can fetch record joining 2 tables.
i have 2 repo below:
public interface aentityrepository extends jparepository<aentity, integer> public interface bentityrepository extends jparepository<bentity, integer>
i want join above 2 entity(aentity, bentity). know can have custom query using below:
@query("select ****** aentity ae") aentity findcustomrrecords();
however can write same kind of query (join query) join. need have separate repository implementing other class.
can please help.
i using mysql.
i understand there separate repository each entity(table)
this common misunderstanding. not want have repository per entity, per aggregate root. see http://static.olivergierke.de/lectures/ddd-and-spring/
regarding specific problem @ hand: creating custom method in repository interface , annotating jpql should trick. like:
@query("select bentity b join b.a b.foo = :foo") aentity getallfooishas(string foo);
you can use join syntax jpql offers in query.
Comments
Post a Comment