JAVA中org.hibernate.TransientObjectException异常分析

org.hibernate.TransientObjectException: org.hepeng.epai.entity.Users
	org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
	org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
	org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:221)
	org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:476)
	org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:2803)
	org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:467)
	org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:190)
	org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
	org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
	org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
	org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
	org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
	org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
	org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
	org.hepeng.epai.dao.GoodsDAO.save(GoodsDAO.java:40)
	org.hepeng.epai.struts.action.GoodsAction.addGoods(GoodsAction.java:162)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
	org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   错误提示说:你在保存对象过程中,该对象有一个属性(外键)关联的另外一个未持久化的对象(未保存的对象);即你关联了一个不存在的记录;
解决方法是先保存"被关联"的那个对象,才能保存先前的那个对象;
当然你也可以在hbm.xml配置文件里在相应的属性配置其cscade属性为"all";

你可能感兴趣的:(java)