excel - Unsaved Transient Instance Hibernate -
although there several questions related exception, folks, not possible duplicate . iterating through multiple excel sheets using apache poi , have utilize jpa perform many 1 relation
for (int = 0; < wb.getnumberofsheets(); i++) { hssfsheet sheet = wb.getsheetat(i); .... if(i=0) { baseclass obj = new baseclass (); obj.setname("name"); session.save(obj) session.gettransaction().commit(); } if(i=3) { foreigclass obj2 = new foreigclass (); obj2.setsection("2a"); baseclass obj = new baseclass (); --> obj2.settransport(obj); // linking foreign keys // error comes here session.save(obj2) }
at marked line, getting next exception:
exception in thread "main" org.hibernate.transientobjectexception: object references unsaved transient instance - save transient instance before flushing: model.ceptransport @ org.hibernate.engine.internal.foreignkeys.getentityidentifierifnotunsaved(foreignkeys.java:294) @ org.hibernate.type.entitytype.getidentifier(entitytype.java:537) @ org.hibernate.type.manytoonetype.isdirty(manytoonetype.java:311) @ org.hibernate.type.manytoonetype.isdirty(manytoonetype.java:321) @ org.hibernate.type.typehelper.finddirty(typehelper.java:294) @ org.hibernate.persister.entity.abstractentitypersister.finddirty(abstractentitypersister.java:4243) @ org.hibernate.event.internal.defaultflushentityeventlistener.dirtycheck(defaultflushentityeventlistener.java:546) @ org.hibernate.event.internal.defaultflushentityeventlistener.isupdatenecessary(defaultflushentityeventlistener.java:232)
can suggest wrong here ? cascading properties fine , works fine if info comes 1 excel sheet.
in below code creating objects foreigclass
& baseclass
, trying save one:
foreigclass obj2 = new foreigclass (); // created foreigclass object obj2.setsection("2a"); baseclass obj = new baseclass (); // created baseclass object obj2.settransport(obj); // linking foreign keys // error comes here session.save(obj2);
so obj2
, obj
in transient state, when phone call session.save(obj2)
checks linked entities , there state before making obj2
persistent state. obj
still in transient state complains error as:
org.hibernate.transientobjectexception: object references unsaved transient instance - save transient instance before flushing: model.ceptransport.
here guess ceptransport
same baseclass
.
to prepare issue, save baseclass
before saving foreigclass
this:
session.save(obj); session.save(obj2);
but if want utilize cascade setting check settings @ foreigclass
, create sure cascade values correct.
excel hibernate apache-poi one-to-many
No comments:
Post a Comment