【问题标题】:Hibernate Transaction information休眠事务信息
【发布时间】:2010-10-17 17:10:18
【问题描述】:

鉴于您有很多域对象,它们都相互交互,了解哪些对象在特定事务中发生了更改将非常有用。

这可能吗?我想基本上这样做:

public void someBusinessLogicMethod(someparams) {
  Session s = getSession();
  Transaction tr = s.beginTransaction()

  domainObject = s.load(...)
  domainObject.setSomethingOrOther(...);
  domainObject.getSomeLink().setSomethingElse(...);
  callSomeOtherBusinessLogicMethod();

  tr.commit();

  /* at this point many objects have changed, Hibernate knows which ones */

  for (Object s : tr.getAffectedObjects(?)) {
    ....
  }
}

这存在吗?

【问题讨论】:

  • 此时很多对象都发生了变化,Hibernate 知道哪些 --- 你是 suuuuure 吗?
  • 为什么有用?你为什么需要这个?根据答案,可能会有解决方案,但您需要澄清。

标签: java hibernate transactions properties


【解决方案1】:

假设您想要为所有更改创建审计条目,您可以使用 Hibernate Listener 或 Interceptor。如果您在正确的时刻挂钩侦听器/拦截器(例如 onFlushDirty),您就可以访问已更改的对象和属性。

更多信息:http://docs.jboss.org/hibernate/core/3.3/reference/en/html/events.html

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2016-03-19
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多