我有两个实体(例如降低尽可能;每个实体有一个ID字段):刷新休眠式
@Entity
public class A {
@Column(nullable = false)
private double foo;
@Formula(value = "foo - (select coalesce(sum(x.foo), 0) from x where x.a_id = id)")
private double bar;
}
和
@Entity
public class X {
@ManyToOne(optional = false)
private A a;
@Column(nullable = false)
private double foo;
}
当我创建一个新的X
( new X()
,beginTransaction()
,save(x)
,commit()
)A.bar的值不刷新。
我认为这是因为旧的(和错误的)值仍然在一级缓存中(没有二级缓存)。我不想调用Session.clear()
,因为此方法似乎会使现有的实体对象无效。我还能做些什么来解决这个问题?
编辑:如这里要求是代码保存X
-objects:
// setters
getSession().beginTransaction(); // getSession() returns the current session
getSession().save(entity); // entity is an instance of X
getSession().getTransaction().commit();
你可以粘贴代码来保存X吗? – Premraj 2011-03-26 13:34:34