mazzystar0 2009-03-24 14:55
浏览 252
已采纳

org.hibernate.TransientObjectException

[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了一下午,希望大家不要再范类似错误了。

  • 写回答

1条回答 默认 最新

  • zhoujuan520 2009-03-24 15:04
    关注

    User类和UserInfo类的关系有点问题.你提供的信息少了一点.把spring配置放出来

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 爬虫爬取网站的一些信息
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错