根据hibernate doc(在http://docs.jboss.org/hibernate/core/3.5/javadoc/org/hibernate/Session.html#update(java.lang.Object))更新方法 void update(Object object)在此处引发HibernateException对象,因为参数被认为处于分离状态。但我尝试了一些例子,其中 传入的对象可以是所以我做的是作为参数在update方法中传递的对象可以处于持久状态还是分离状态?
person = (Person)session. get(Person.class,1);
person.setName("scott");
// At this point of time person is in persistent stage as it has adentifier attached to it and also attached to session.
session.update(person);
它成功更新。 因此,根据我的理解,传递对象作为参数更新方法可以处于持久状态或分离状态吗?
'update()'只有效果,它应该只在分离的对象上工作。 –