public static void bindNativeQuery(NamedNativeQuery queryAnn, Mappings mappings, boolean isDefault) {
if ( queryAnn == null ) return;
//ResultSetMappingDefinition mappingDefinition = mappings.getResultSetMapping( queryAnn.resultSetMapping() );
if (BinderHelper.isEmptyAnnotationValue(queryAnn.name())) throw new AnnotationException(
"A named query must have a name when used in class or package level");
NamedSQLQueryDefinition query;
String resultSetMapping = queryAnn.resultSetMapping();
QueryHint[] hints = queryAnn.hints();
String queryName = queryAnn.query();
if ( !BinderHelper.isEmptyAnnotationValue( resultSetMapping ) ) {
//sql result set usage
query = new NamedSQLQueryDefinition(
queryAnn.name(),
queryName,
resultSetMapping,
null,
getBoolean( queryName, "org.hibernate.cacheable", hints ),
getString( queryName, "org.hibernate.cacheRegion", hints ),
getTimeout( queryName, hints ),
getInteger( queryName, "org.hibernate.fetchSize", hints ),
getFlushMode( queryName, hints ),
getCacheMode( queryName, hints ),
getBoolean( queryName, "org.hibernate.readOnly", hints ),
getString( queryName, "org.hibernate.comment", hints ),
null,
getBoolean( queryName, "org.hibernate.callable", hints )
);
}
else if ( !void.class.equals( queryAnn.resultClass() ) ) {
//class mapping usage
//FIXME should be done in a second pass due to entity name?
final NativeSQLQueryRootReturn entityQueryReturn =
new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
query = new NamedSQLQueryDefinition(
queryAnn.name(),
queryName,
new NativeSQLQueryReturn[] { entityQueryReturn },
null,
getBoolean( queryName, "org.hibernate.cacheable", hints ),
getString( queryName, "org.hibernate.cacheRegion", hints ),
getTimeout( queryName, hints ),
getInteger( queryName, "org.hibernate.fetchSize", hints ),
getFlushMode( queryName, hints ),
getCacheMode( queryName, hints ),
getBoolean( queryName, "org.hibernate.readOnly", hints ),
getString( queryName, "org.hibernate.comment", hints ),
null,
getBoolean( queryName, "org.hibernate.callable", hints )
);
}
else {
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
}
if ( isDefault ) {
mappings.addDefaultSQLQuery( query.getName(), query );
}
else {
mappings.addSQLQuery( query.getName(), query );
}
LOG.debugf( "Binding named native query: %s => %s", queryAnn.name(), queryAnn.query() );
}