我遇到了在启用EHcache的情况下从Hibernate获取对象的问题。 这个
这是我关注类
的hbm.xml片段<class name="FinanceFacility" table="FIN_FACILITY" discriminator-value="FinanceFacility">
<cache usage="read-write" region="financeFacilityCache"/>
<set name="borrowers" access="property" table="FIN_FACILITY_BORROWERS" fetch="subselect" lazy="false" cascade="all,delete-orphan">
<cache usage="read-write" region="financeFacilityCache"/>
<key column="FIN_FACILITY_ID"/>
<element column="GROUP_COMPANY_ID" type="GuidType"/>
</set>
</class>
这是通过Hibernate进行的API调用。
@Override
@Cacheable(cacheName = "assignableFacilityCache") // NOSONAR
public List<FinanceFacility> getAllWhereInventoryCanBeAssigned()
{
LOG.info("Getting all facilities where inventory can be assigned...");
List<QueryParam> params = new ArrayList<QueryParam>();
List<FinanceFacility> facilities = getMultipleEntities("FinanceFacility.findWhereInventoryCanBeAssigned", params);
// Set the parents
for (FinanceFacility facility : facilities)
{
facility.setParentFacility(getPathTo(facility.getParentRef()));
}
LOG.info("getAllFacilities() found " + facilities.size() + " Facility(s)");
return facilities;
}
在正常情况下,运行正常。但在某些并发访问期间,我得到以下错误
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Unable to resolve owner of loading collection [[com.xxx.yyy.internal.model.facilities.FinanceFacility.borrowers#1a21f938e94f4ba2a36a3e973845175e]] for second level caching
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1389) ~[hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317) ~[hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Final]
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255) ~[hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Final]
at com.xxx.yyy.repository.database.AbstractEntityRepository.getMultipleEntities(AbstractEntityRepository.java:65) ~[classes:na]
知道问题是什么吗?如果您需要更多信息,请与我们联系。
答案 0 :(得分:1)
找到它
我必须删除fetch =&#34; subselect&#34;从hbm映射中的设置中获取它的工作原理。 我用批量大小替换它以保持优化。