Say you have a Car with a collection of Tires.
@Entity
public class Car {
private Long id;
@OneToMany(mappedBy = "car")
private Set<Tire> tires = new HashSet<>();
}
@Entity
public class Tire {
private Long id;
...
}
Now if you want to add a new Car and add existing Tires you could go fetch the entire existing Tire Entities to populate the Car's Set.
Is is possible to simply have some Tire IDs and save the Car without fetching the entire Tire entity(ies) into memory first? Is there a way to save it with just a Tire Id if it were just a Single Tire instance instead of a Set? Using JPA and the Criteria API, or maybe JPQL.