[code]javax.servlet.ServletException: org.springframework.dao.InvalidDataAccessApiUsageException: com.entity.User; nested exception is org.hibernate.TransientObjectException: com.entity.User
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
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)
com.util.FilterClass.doFilter(FilterClass.java:24)
root cause
org.springframework.dao.InvalidDataAccessApiUsageException: com.entity.User; nested exception is org.hibernate.TransientObjectException: com.entity.User
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:633)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:377)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:338)
com.dao.daoimpl.BodycheckDaoImpl.adduserinfo(BodycheckDaoImpl.java:42)
com.delegate.delegateimpl.BodycheckdelegateImpl.adduserinfo(BodycheckdelegateImpl.java:24)
com.web.struts.action.BodyCheckAction.adduserinfo(BodyCheckAction.java:69)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
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)
com.util.FilterClass.doFilter(FilterClass.java:24)
root cause
org.hibernate.TransientObjectException: com.entity.User
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.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:338)
com.dao.daoimpl.BodycheckDaoImpl.adduserinfo(BodycheckDaoImpl.java:42)
com.delegate.delegateimpl.BodycheckdelegateImpl.adduserinfo(BodycheckdelegateImpl.java:24)
com.web.struts.action.BodyCheckAction.adduserinfo(BodyCheckAction.java:69)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
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)
com.util.FilterClass.doFilter(FilterClass.java:24)
[/code]
帮我看看呢
我是用spring管理Hibernian和struts的
是建立有关系的
[code]
public Integer adduserinfo(final Userinfo userinfo) {
Integer num=(Integer)this.getHibernateTemplate().execute(new HibernateCallback()
{
public Object doInHibernate(Session s)throws HibernateException,SQLException
{
return s.save(userinfo);
}
});
[/code]
userinfo包含有user的信息。
我看了意思就是 userinfo 中的user 是transient状态的, 不知道该怎么解决
[b]问题补充:[/b]
userinfo配置的是多对一,
只在userinfo中配置了private User user;
user中没有关联userinfo
[b]问题补充:[/b]
知道怎么回事了
update userinfo 之前 执行了[color=red]userinfo.setUser(new User()),[/color]此时的userinfo是persistent状态,而user属性是一个transient状态的对象,并且cascade为默认的"none"(如果是all那么会试图创建一个新的User对象),所以无法更新userinfo。
都是 spring 的 formbackingObject 惹的麻烦,害我debuge了一下午,希望大家不要再范类似错误了。