Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.2K
Vistas
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?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda