什么可能导致休眠尝试解析包路径并且在这样做时也会失败:
Exception in thread "Timer-9" org.hibernate.QueryException: could not resolve property: codeto of: citylist_AUD [select new list(ee, e) from citylist_AUD ee, ee.codeto.wes.Citylist_AUD e where ee.originalId.citylist_id = e.originalId.id and ee.originalId.Road_id = :Road_id and e.originalId.REV.id = (select max(e2.originalId.REV.id) from ee.codeto.wes.Citylist_AUD e2 where e2.originalId.REV.id <= :revision and e.originalId.id = e2.originalId.id) and ee.originalId.REV.id = (select max(ee2.originalId.REV.id) from road_city_AUD ee2 where ee2.originalId.REV.id <= :revision and ee.originalId.Road_id = ee2.originalId.Road_id and ee.originalId.citylist_id = ee2.originalId.citylist_id) and ee.REVTYPE != :delrevisiontype and e.REVTYPE != :delrevisiontype]
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1465)
at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:315)
at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:487)
at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:611)
at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:263)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:210)
at org.hibernate.hql.ast.tree.FromReferenceNode.recursiveResolve(FromReferenceNode.java:101)
at org.hibernate.hql.ast.tree.FromReferenceNode.recursiveResolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromReferenceNode.recursiveResolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromReferenceNode.recursiveResolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromReferenceNode.recursiveResolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromElementFactory.evaluateFromElementPath(FromElementFactory.java:172)
at org.hibernate.hql.ast.tree.FromElementFactory.createFromElementInSubselect(FromElementFactory.java:134)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:107)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:327)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3441)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4479)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3947)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2047)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1975)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1972)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1972)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1972)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:831)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:617)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:256)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
at org.hibernate.envers.entities.mapper.relation.query.TwoEntityQueryGenerator.getQuery(TwoEntityQueryGenerator.java:128)
at org.hibernate.envers.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:62)
at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50)
at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.iterator(CollectionProxy.java:70)
at ee.codeto.wes.Helper.getListSum(Helper.java:329)
我正在使用休眠 3.6.9
一切正常,直到我为两个被审计实体之间的多对多关系引入审计。基本上是 Road.java:
@Audited
@Entity
@Table(name = "ROAD")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Road {
...
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "ROAD_CITYLIST", joinColumns = { @JoinColumn(name = "ROAD_ID") }, inverseJoinColumns = { @JoinColumn(name = "CITYLIST_ID") })
@Fetch(FetchMode.SUBSELECT)
@Cache(usage = CacheConcurrencyStrategy.NONE)
private Set<CityList> citylists;
...
}
我用同样的逻辑做了一个类似的小测试并且成功了。我真的很感激任何帮助或朝着正确方向轻推。如果需要其他信息,只需命名,我可以提供。