【发布时间】:2012-09-20 08:27:58
【问题描述】:
我有一门课
<class name="Goods">
...
<map name="names" lazy="false" fetch="join">
<key not-null="true" />
<map-key column="LANGUAGE_CODE" type="language" length="2"/>
<composite-element class="Goods$Names">
<property name="name" not-null="true" type="text"/>
<property name="description" type="text"/>
</composite-element>
</map>
...
</class>
当我尝试像这样按名称搜索商品时出现问题:
session.createQuery("select g from Goods g where g.names[:lang].name = 'Some goods name'")
javax.servlet.ServletException: java.lang.IllegalArgumentException: Cannot create element join for a collection of non-entities!
Hibernate 真的不可能做到这一点吗?
我真的需要将商品名称设为具有自己 ID 的实体吗?
有什么解决办法吗?
【问题讨论】:
-
为什么不把它做成实体呢?
-
我不想要实体,因为我不想要额外的 id 列。所以我的第一个方法是创建具有复合 id 的实体。但最后我明白了我必须如何创建我的查询。所以这个查询很简单: select g from Goods g join g.names names with index(names) = :lang where names.name='some goods names'
标签: java hibernate collections