我想保留以下事件类:
public class Event {
private Long id;
private LocalizableString name = new LocalizableString();
/* setters and getters */
}
用hibernate进入数据库。这是“LocalizableString”类:
public class LocalizableString {
private Map<Locale, String> values = new HashMap<Locale, String>();
/* setters and getters */
}
所以这是我创建的映射:
<hibernate-mapping>
<class name="path.to.my.Event" table="MyEventTable">
<id name="id" column="Un_ID" type="java.lang.Long">
<generator class="path.to.my.IDGenerator" />
</id>
<component name="name">
<map name="values" table="NamesOfMyEvents">
<key column="event_id"/>
<map-key column="locale" type="java.util.Locale"/>
<element column="value" type="string"/>
</map>
</component>
</class>
</hibernate-mapping>
起初一切看起来都很好。我可以用大量的名称翻译填充我的名称属性的映射,我可以保留这些名称,我可以从数据库中检索事件。使用 SQL 直接查看我的数据库,一切看起来都很好。
但后来到了我想使用投影并执行以下 HQL 查询的那一天:
select e.name from Event e where id = :id
现在我得到以下异常:
java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.hql.ast.util.ColumnHelper.generateScalarColumns(ColumnHelper.java:62)
at org.hibernate.hql.ast.tree.DotNode.setScalarColumnText(DotNode.java:667)
at org.hibernate.hql.ast.tree.SelectClause.renderScalarSelects(SelectClause.java:375)
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:250)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:831)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:619)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:672)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
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:94)
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:1651)
嗯,这很糟糕。我能做些什么吗?我正在使用休眠 3.3.2。我知道这个版本已经很老了,但升级对我来说并不容易。因此,如果这是一个错误,非常感谢一种解决方法。知道哪个版本修复了问题也将是有用的信息。