JPA類是這樣的:更新在休眠@OneToOne映射一個表
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」。
我得到異常:
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "alert_type_id" violates not-null constraint Detail: Failing row contains (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).
請建議
什麼是'JpaAlertType'和什麼是'entity.alertType'的vakue? – talex