Hello All,
Today I'm sharing my learning experience, to solve the one issue while working with Springboot & Hibernate/JPA.
We often get the below error.
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.oracle.dto.Asset
at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:347) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
The solution of this issue is to explicitly save the referred data.
I've solved this issue with the below code.
Transaction tx=session.beginTransaction();
session.save(citizen);
for (Asset asset:citizen.getAssetList()) {
session.save(asset);
}
tx.commit();