我正在使用一个非常旧的数据库,我必须检索一些特定的数据。我使用 sql server 和休眠。我编写了一个名为 Language 的类,带有一个 guid(一个人的 id)和一组已知语言。我必须检索数据库中每个人都知道的所有语言,但我不知道我是否可以用特定的本机查询填充语言集。
@NamedNativeQuery(
name = "queryLanguages",
query = "SELECT c.GUIDPersona as guid, d.Caption as language" +
" FROM " +
" Competenze c " +
" INNER JOIN " +
" DomainItemsCaption d " +
" ON (c.IdConoscenza = d.ItemID) " +
" WHERE " +
" d.DomainName = 'Conoscenza' AND " +
" d.Caption LIKE 'Lingue ~ %'",
resultSetMapping = "Languages"
)
@SqlResultSetMapping(
name = "Languages",
entities = {
@EntityResult(
entityClass = Language.class,
fields = {
@FieldResult(name="guid", column="guid"),
@FieldResult(name="languages", column="language")
}
)
}
)
public class Language {
private String guid;
private Set<String> languages;
...
}
我可以用特定的本地查询填充“语言”字段,以检索与实体关联的人的所有已知语言吗?