简体   繁体   中英

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?

@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;
}

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

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM