/**
* Parse @NamedNativeQuery.
*/
private void parseNamedNativeQueries(AnnotatedElement el,
NamedNativeQuery... queries) {
QueryMetaData meta;
for (NamedNativeQuery query : queries) {
if (StringUtils.isEmpty(query.name()))
throw new MetaDataException(_loc.get("no-native-query-name",
el));
if (StringUtils.isEmpty(query.query()))
throw new MetaDataException(_loc.get("no-native-query-string",
query.name(), el));
if (_log.isTraceEnabled())
_log.trace(_loc.get("parse-native-query", query.name()));
meta = getRepository().searchQueryMetaDataByName(query.name());
if (meta != null) {
Class<?> defType = meta.getDefiningType();
if ((defType != _cls) && _log.isWarnEnabled()) {
_log.warn(_loc.get("dup-query", query.name(), el, defType));
}
continue;
}
meta = getRepository().addQueryMetaData(null, query.name());
meta.setLanguage(QueryLanguages.LANG_SQL);
meta.setQueryString(query.query());
Class<?> res = query.resultClass();
if (ImplHelper.isManagedType(getConfiguration(), res))
meta.setCandidateType(res);
else if (!void.class.equals(res))
meta.setResultType(res);
if (!StringUtils.isEmpty(query.resultSetMapping()))
meta.setResultSetMappingName(query.resultSetMapping());
for (QueryHint hint : query.hints())
meta.addHint(hint.name(), hint.value());
meta.setSource(getSourceFile(), (el instanceof Class) ? el : null,
SourceTracker.SRC_ANNOTATIONS, getSourceFile() == null ? "" : getSourceFile().getPath());
if (isMetaDataMode())
meta.setSourceMode(MODE_META);
else if (isMappingMode())
meta.setSourceMode(MODE_MAPPING);
else
meta.setSourceMode(MODE_QUERY);
}
}