有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么hibernate不读取事务中的更新?

我有一个使用Spring和Hibernate的应用程序,以及类似的场景

class Sheet{
   Set<Entry> entries;
}

class Entry{
   Sheet belongsTo;
   String name;
}


class Service{
  @Autowired GenericDao dao;

  @Transactional(readOnly=false)
  private void doSomething(){
     Sheet s1 = new Sheet();
     dao.create(s1);

     Entry a = new Entry();
     a.setSheet(s1);
     dao.create(a);

     // Now I expect, that when updating my sheet there should be my Entry 'a' in the PersistentBag of the sheet
     dao.refresh(s1)
     s1.getEntries(); // <-- entry 'a' is not in the List.
  }
}

当然,类中有setter/getter和必要的注释

如果我在另一个服务调用中调用s1.getEntries()(使用一个新事务,并且在提交上述事务之后),我的工作表列表中有条目'a'

我想知道,为什么我不能在同一个事务中读取我在事务中所做的更改。 为什么PersistentBag没有更新

我正在使用Hibernate 4.3.5和Spring 4.0.5


共 (0) 个答案