我有一个Spring JPA 2实体类
@Entity
@Table(name = "hotels")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Hotel {
@Id
@Column(name = "hotelId")
@JsonProperty("hotel_id")
private Integer hotelId;
@OneToOne(targetEntity = Location.class, cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
@JoinColumn(name = "location_id")
@JsonProperty("location")
private Location location;
....
}
并且Location类以
的形式给出 @Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class Location {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer location_id;
@Column
@JsonProperty("latitude")
private Double latitude;
@Column
@JsonProperty("longitude")
private Double longitude;
}
当我正在hotelRepository.save(hotel)
时,我正在Column 'location_id' cannot be null
。我通过使用REST Web服务来获取填充的Hotel
。
任何人都可以帮助我!不胜感激!