English 中文(简体)
找到共享的收藏引用 : 在使用同一用户会话平行交易时
原标题:Found shared references to a collection: when using transactions in parallel from same user session

I am using hibernate 3.3 with spring 3.0.5 and using JPA transaction manager. My scenario is a ui page invoking two get methods on service layer to render two regions in UI, Requests are parallel ajax requests. The get methods in service layer return two separate lists of same entity.

List<Car> getCarsA();
List<Car> getCarsB();

我配置了JPA交易经理如下:

<tx:method name="get*" read-only="true" propagation="REQUIRED"/>

Problem : when the hibernate/JPA calls flush after each service method is over, there is potentially some collection (via many-to-many mappings) which is shared between the two lists returned by the methods and hence the exception. I am also using OpenEntityManagerInViewFilter. I do not run into this error if I call the methods serially.

问题回答

休眠会话对象不使用线索安全 。 您要么必须使用每个线索自己的会话实例, 要么您必须同步访问会话实例, 与 java 同步 块同步 。

在网络环境中,您应该每浏览器会话至少使用一个冬眠会话。同一浏览器会话的访问可以是 同步化 ,也可以使用不止一个会话(当您同时获取不同区域的 UI 时,我会与 同步化 同步化 同步,除非一个查询需要相当长的时间,其他查询不应等待) 。

注意:某届会议的最新情况在其他届会中无法直接看到(就本案而言,在另一届会中已经暗藏)。





相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签