简体   繁体   中英

Hibernate OneToMany Insert fails Exception

Stuck with a odd Cannot insert the value NULL, Insert Fails Exception, Thnaks in advance for all the help.

Below is my mapping:

Entity Class Role:

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

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

Feature Entity Class:

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

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

Error:

 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)

And yes, i have called the getter setters to set the parent child object relations appropriately

Resolved this. Problem was with two different EntityManager contexts that were conflicting, although the exception relates nothing to what the problem was.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM