I need to insert a null value in foreign key column, but I get this error: Is it possible?
Exception
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing: com.company.project.model.ConceptoGasto.conceptoGasto -> com.company.project.model.ConceptoGasto; nested exception is java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing: com.company.project.model.ConceptoGasto.conceptoGasto -> com.company.project.model.ConceptoGasto
Entity
//----------------------------------------------------------------------
// ENTITY PRIMARY KEY ( BASED ON A SINGLE FIELD )
//----------------------------------------------------------------------
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", nullable=false)
private Integer id;
....
@ManyToOne (optional = true)
@JoinColumn(name="idPadre", referencedColumnName="id", nullable=true)
private ConceptoGasto conceptoGasto;
.....
Method
JpaOperation operation = new JpaOperation() {
@Override
public Object execute(EntityManager em) throws PersistenceException {
T managedEntity = em.merge(entityToSave);
//em.refresh(managedEntity);
return managedEntity;
}
} ;