什么可能导致hibernate尝试解析包路径,并且在执行此操作时也会失败:
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)
我正在使用hibernate 3.6.9
在我为两个审计实体之间的ManyToMany关系引入审计之前,一切正常。基本上是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;
...
}
我用相同的逻辑做了类似的小测试并且成功了。我真的很感激任何帮助或推动正确的方向。如果需要其他信息,请为其命名,我可以提供。
答案 0 :(得分:0)
回答我自己的问题:
这个bug出现在3.6的hibernate envers中,在某些情况下,从爱沙尼亚域名派生的包名称(例如ee.codeto.foo)遇到了麻烦。由于hibernate在构建查询期间某些时候使用了“ee”作为别名,并且在使用包的完整类名(现在总是)的情况下,hibernate认为包装名称中的下一部分在“ee之后” “是列名。
在hibernate的更高版本中,这个问题得以解决。可能不是因为这个爱沙尼亚域名,而是因为更好的别名用法。使用“ee_ ”代替“ee”。因此,如果您将包含“ee _”的包作为包名称的第一部分并碰巧使用hibernate envers并碰巧使用多对多映射并碰巧拥有不幸的是,hibernet试图在包中使用完整的类名,那么这个错误很可能是你造成的。