使用Spring JPA 2存储库尝试保存时,location_id不能为null

时间:2015-05-22 18:43:28

标签: jpa spring-data-jpa

我有一个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

任何人都可以帮助我!不胜感激!

0 个答案:

没有答案