2014-01-23 69 views
0

卡住奇數無法插入值NULL,插入失敗異常,提前Thnaks的所有幫助。休眠OneToMany插入失敗異常

下面是我的映射:

實體類角色:

@OneToMany(mappedBy = "role") 
public Set<Feature> getFeatures() { 
    return features; 
} 

public void setFeatures(Set<Feature> features) { 
    this.features = features; 
} 

功能實體類:

@ManyToOne 
@JoinColumn(name = "ROLE_ID", nullable = false) 
public Role getRole() { 
    return role; 
} 

public void setRole(Role role) { 
    this.role = role; 
} 

錯誤:

Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Cannot insert the value NULL into column 'ROLE_ID', table 'FEATURE'; column does not allow nulls. INSERT fails. 
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] 
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] 
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] 
at org.hibernate.ejb.AbstractEntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1481) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] 
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:109) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] 
at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] 
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76) 
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273) 
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93) 
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164) 
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165) 

是的,我已經叫吸氣劑的制定者設置親子對象關係

+1

請發送正在做保存操作(服務或dao)的代碼。 –

+0

請發佈您的代碼以使我們能夠爲您提供幫助。否則它在黑暗中拍攝並猜測工作 – Hrishikesh

+0

@JoinColumn(name =「ROLE_ID」,nullable = false)表示如果該列爲空,則無法存儲該列,因此可能在您插入記錄時爲空,這是約束禁止的。但記住ID應該有一個值,除了添加父子關係之外,這個錯誤讓我覺得在您嘗試保存的時刻父代的@Id沒有被設置。 – Koitoer

回答

0

解決了這個問題。問題在於兩個不同的EntityManager上下文是衝突的,儘管這個例外與問題無關。