Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
join more than one table in spring jparepository

I am trying to fetch record by doing a join. I am new to spring jparepository. I understand that there is separate repository for each entity(table) where when i implement i need to define the entity and datatype of primary key.

Could anyone please suggest how can I fetch record by joining two tables.

I have two repo as below:

public interface AEntityRepository extends JpaRepository<AEntity, Integer>

public interface BEntityRepository extends JpaRepository<BEntity, Integer>

I want to join above two entity(AEntity, BEntity). I know I can have custom query using something like below:

@Query("SELECT ****** FROM AEntity ae")
AEntity findCustomrRecords();

However can I write the same kind of query (join query) with join. Do i need to have a separate repository implementing some other class.

Can anyone please help.

I am using mysql.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I understand that there is separate repository for each entity(table)

This is a very common misunderstanding. You do not want to have a repository per entity, but per aggregate root. See http://static.olivergierke.de/lectures/ddd-and-spring/

Regarding your specific problem at hand: Creating a custom method in your repository interface and annotating it with a JPQL should do the trick. So you get something like:

@Query("select a from BEntity b join b.a a where b.foo = :foo")
AEntity getAllFooishAs(String foo);

You can use any join syntax JPQL offers in the query.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!