0
比方说,我有2个实体如何坚持春季数据JPA实体没有得到相关的对象
@Entity
@Table(name = "users")
public class User implements Serializable {
private User() {
}
... other fields omitted ...
@OneToMany(mappedBy = "user")
private List<Car> cars;
}
和
@Entity
@Table(name = "cars")
public class Car implements Serializable {
public Car() {
}
... Other fields omitted ...
@Column(name = "id")
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@JsonIgnore
@JoinColumn(name = "user_id")
@ManyToOne
private User user;
}
现在,每当我打电话救我CarRepository,它需要我在用户字段上具有用户对象。这样的话,我还是要调用findById方法在我UserRepository像
...
car.setUser(userRepository.findById(userId));
carRepository.save(car);
...
是否有春天JPA的数据只保存使用用户id,在那里我没有坚持在之前得到一个用户对象的方式汽车对象?