[英]update one table in @onetoone mapping in hibernate
jpa類是這樣的:
public class JpaAlertConfiguration{
...
@OneToOne(fetch = FetchType.EAGER)
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "alert_type_id", nullable = false, referencedColumnName = "id", insertable = false, updatable = false)
private JpaAlertType alertType;
}
從此類方法調用創建實體。
@Override
@Transactional
public JpaAlertConfiguration createEntity(JpaAlertConfiguration entity) throws Exception
{
getAuthorizer().checkCreate(ENTITY_NAME);
validateFields(entity);
getAuthorizer().checkAccountAccess(entity.getAccount().getId(), null);
entity = attachAssociatedEntities(entity);
// entity.setStatusColumns(new StatusColumns().setStatus(ResourceStatus.Disabled));
entity = super.createEntity(entity);
entity = transformResult(entity);
return entity;
}
我確保在調用此行之前, entity = super.createEntity(entity);
,將填充JpaAlertType id值,該值僅是alertConfig表的“ alert_type_id”。
我正在例外:
由以下原因引起:org.postgresql.util.PSQLException:錯誤:“ alert_type_id”列中的空值違反了非空約束詳細信息:失敗行包含(3,Speed Alert,Speeding Alert,5,t,null,Enabled,0、2016 -09-06 17:56:30.556 + 05:30,2016-09-06 17:56:30.58 + 05:30,2016-09-06 17:56:30.556 + 05:30,null,f,f) 。
請建議
我認為您缺少JPA持久性命令,請參見下面有關JPA一對一插入的鏈接,希望這可以有所幫助。
問題已解決:實際上,在我的場景中,我正在調用通用的createEntity方法。 不確定,但是我只是從JPAAlertConfiguration類的alertType變量中刪除了所有復雜注釋
@OneToOne(optional = false)
@JoinColumn(name = "alert_type_id")
private JpaAlertType alertType;
而且有效。 不管怎么說,多謝拉
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.