我使用Spring Data REST和JPA。我有一个用户实体与另一个叫做AccountStatus的多对一关系建模在一个单独的RDBMS表中。 JSON表示如下:如何更新与Spring Data REST的@ManyToOne关系?
{
"id": "123"
"username": "user1",
"accountStatus": {
"id": "1",
"status": "Active"
}
}
在用户实体的关系是:
@ManyToOne(optional = false)
@JoinColumn(name = "account_state")
@Getter @Setter private AccountState accountState;
现在我尝试使用上/用户/ 123和有效载荷补丁请求更改账户状态:
{"accountState":{"id":0}}
但我得到一个错误:
"identifier of an instance of com.domain.account.AccountState was
altered from 1 to 0; nested exception is org.hibernate.HibernateException:
identifier of an instance of com.domain.account.AccountState was
altered from 1 to 0"
我也尝试使用@ HandleBeforeSave/@ HandleBeforeLinkSave从存储库中提取新的AccountState,并取代user.accountStatus而没有成功。
我在做什么错?
的[休眠可能重复:如何解决“实例标识符从X更改为Y”?](http://stackoverflow.com/questions/4179166/hibernate-how-to-fix-identifier-of-an-instance-altered-from-x-to- y) – Makoto
@Makoto,我想另外一个问题是关于改变一个拥有实体的PK,我的问题是改变一个没有在用户和AccountState之间定义级联的子关系。 – florind