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

1.2K
Views
Spring Data JPA save child without fetch the parent

How to save child entity with Spring data JPA repositories if you know the parent Id?

For example if we have one to many relation:

@Entity
public class Customer {
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    private String firstName;
    private String lastName;
    @ManyToOne
    private CustomerCategory category;
}

@Entity
public class CustomerCategory {
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    private String name;
}

One can do something like:

CustomerCategory someCategory = customerRepository.findOne(1L);// how to skip that line. The id should be enough. 
Customer cust = new Customer("Evgeni", "Dimitrov", someCategory);           
customerRepository.save(cust);

JPA can do load(just create a proxy and set the Id) instead of 'get'(select from the DB). Is that possible with Spring Data JPA?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Forget Id. You are now at the Object level of ORM (ObjectRelationMapping). Objects are composed of other objects. NO IDs.

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!