Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:03:19+00:00 2026-06-09T14:03:19+00:00

While using Spring Data JPA in an application, you typically define your entities (@Entity)

  • 0

While using Spring Data JPA in an application, you typically define your entities (@Entity) and write a Repository Interface (which extends CrudRepository) and do some additional configuration which is out of scope for this question.

For example,

@Entity
public class Product {
    // code removed for brevity
}

public interface ProductRepository extends CrudRepository<Product, Long> {
    // code removed for brevity
}

Now if I’ve multiple entities like above and need to design a service API like searchByProductAndUserAndLocation (say all three are database tables), how should I be doing this in Spring data JPA? Assume that I write entity classes for Quantity/Cost as well. Obviously, I need to join the tables on some criteria (using foreign key), but I’m not clear on which repository should hold such queries as I feel that there is no specific owner repository/class here.

Also, I could expose the data by ProductService, LocationService and so on and then combine the results, but I wouldn’t be utilizing the database layer join or other optimizations eventually impacting the application performance.

I’m sure this is a very common use-case, what’s the general practice for this?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:03:20+00:00Added an answer on June 9, 2026 at 2:03 pm

    I believe it’s reasonable to assign your method to the repository depending on the return type of the method, e.g.:

    public interface ProductRepository extends CrudRepository<Product, Long> {
      List<Product> searchByUserAndLocation(User user, Location location); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Spring Framework . While writing custom queries, I am unable check
I have been using spring for a while as my IOC. It has also
new to Laravel (coming from Java spring), while using Route::get('/', function() { return Hello
I have been using the Spring RestTemplate for a while and I consistently hit
I am using JPA to persist data. I am new to whole of Java-ee
I'm writing a small demo application in Java using Spring, that needs to have
While using the Entity Framework I have split it out to it's own project:
Hi all patient developers using spring data graph. Since there is so less documentation
a little background here.I've been working with spring+hibernate(JPA+Session)+maven for while now.I'm used to Hibernate
I am getting a weird problem while using scanf() to store data into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.