2016-09-06 91 views
0

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).

請建議

+0

什麼是'JpaAlertType'和什麼是'entity.alertType'的vakue? – talex

回答

0

我認爲你缺少JPA持續順序,可以看看下面的JPA one-to-one insert的鏈接,我希望這可以幫助。

+0

謝謝卡邁勒。在發佈我的問題之前,我檢查了該鏈接。沒有真正的幫助。但我設法以某種方式解決它。也發佈答案。 – Kusum

0

問題已解決: 實際上,在我的場景中,我調用了通用的createEntity方法。不知道,但我只是刪除了所有複雜的註解從 警告類型變量JPAAlertConfiguration類

@OneToOne(optional = false) 
@JoinColumn(name = "alert_type_id") 
private JpaAlertType   alertType; 

和它的工作。無論如何感謝