Hi
Im facing a rather odd situation here. I get a TransientObjectException when i try to save an object, where the attribute is actually null. I allowed this attribute to be null and the relation optional.
I specially ensured that the attribute is really null when i try to save it.
Heres the stack:
Code:
Exception in thread "Thread-17" org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: ch.sisa.reportit.business.ReportItBlob; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ch.sisa.reportit.business.ReportItBlob
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:654)
at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:374)
at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$afterReturning$org_springframework_transaction_aspectj_AbstractTransactionAspect$3$2a73e96c(AbstractTransactionAspect.aj:78)
at ch.sisa.reportit.business.reports.execution.ReportExecutionService.saveReportingResult(ReportExecutionService.java:212)
at ch.sisa.reportit.business.reports.execution.ReportExecutionService$1.run(ReportExecutionService.java:523)
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ch.sisa.reportit.business.ReportItBlob
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:265)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:275)
at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3378)
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:520)
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:230)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
... 6 more
And heres the code snip of the attribute:
Code:
// workarround for lazy property fetch
//@Cascade(value=org.hibernate.annotations.CascadeType.DELETE)
@ManyToOne(fetch = FetchType.LAZY,optional=true)
@JoinColumn(name = "dataFetchId",nullable=true)
private ReportItBlob data = null;
Can someone tell me why this happens? I dont get it...
Bonus question:
As you can see, i used a @ManyToOne here. The thing about it is, ReportItBlob is used whenever i need a lazy loaded Lob object, and is therefore spread all over my beans. I dont like the idea of having dozens of empty @OneToMany in the ReportItBlob. Problem is, when i try to save/delete the @ManyToOne side of the relationship before saving/deleting the ReportItBlob i also get an exception like the one metioned before. This requires coding on the service side to manually clean the object.
Can someone tell me a more sophisticated way to solve this without this stupid code overhead?
Thanks in advance