java 中如何临时保存某输入值_java – 非空属性引用瞬态值 – 在当前操作之前,必须保存临时实例...

我有2个域模型和一个Spring REST控制器,如下所示:

@Entity

public class Customer{

@Id

private Long id;

@OneToOne(fetch = FetchType.EAGER)

@JoinColumn(name="COUNTRY_ID", nullable=false)

private Country country;

// other stuff with getters/setters

}

@Entity

public class Country{

@Id

@Column(name="COUNTRY_ID")

private Integer id;

// other stuff with getters/setters

}

Spring REST控制器:

@Controller

@RequestMapping("/shop/services/customers")

public class CustomerRESTController {

/**

* Create new customer

*/

@RequestMapping( method=RequestMethod.POST)

@ResponseStatus(HttpStatus.CREATED)

@ResponseBody

public com.salesmanager.web.entity.customer.Customer createCustomer(@Valid @RequestBody Customer customer, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {

customerService.saveOrUpdate(customer);

return customer;

}

// other stuff

}

我正在尝试使用以下JSON作为身体调用上面的REST服务:

{

"firstname": "Tapas",

"lastname": "Jena",

"city": "Hyderabad",

"country": "1"

}

国家代码1已在国家表格中.问题是当我打电话给这个服务下面的错误:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: Not-null property references a transient value - transient instance must be saved before current operation: com.test.model.Customer.country -> com.test.model.Country; nested exception is java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: Not-null property references a transient value - transient instance must be saved before current operation: com.test.model.Customer.country -> com.test.model.Country

任何帮助将不胜感激!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值