I'm working with a very old database and I've to retrieve some specific data. I use sql server and hibernate. I've written a class named Language with a guid (id of a person) and a set known languages. I've to retrieve all languages known by each person in the db, but I don't know if I can fill the languages set with a specific native query.
@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;
...
}
Can I fill the "languages" field with a specific native query retrieving all known languages for the person associated to the entity?