org.hibernate.TransientObjectException: object references an unsaved transient instance

Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.wondersgroup.hs.framework.persistence.domain.Person  at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)  at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)  at org.hibernate.type.EntityType.replace(EntityType.java:253)  at org.hibernate.type.AbstractType.replace(AbstractType.java:153)  at org.hibernate.type.TypeFactory.replace(TypeFactory.java:515)  at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:377)  at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:179)  at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:240)  at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)  at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)  at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)  at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)  at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)  at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:827)  at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)  ... 68 more

这个错误主要是因为保存一个对象之前,这个对象里面含有其他空的对象,无法找到 解决:根据b对象在数据库中的ID new一个b对象,然后调用a对象的setB(xxx)或者设置a中的b对象为null。

你可能感兴趣的:(org.hibernate.TransientObjectException: object references an unsaved transient instance)