HHH-8125 Support for pure native scalar queries in metamodel

This commit is contained in:
Brett Meyer 2013-04-01 16:38:10 -04:00
parent 832a60c9c1
commit 9a4a760280
3 changed files with 31 additions and 34 deletions

View File

@ -25,16 +25,13 @@ package org.hibernate.metamodel.internal.source.annotations.global;
import java.util.Collection;
import java.util.HashMap;
import javax.persistence.LockModeType;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.logging.Logger;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.CacheMode;
@ -45,7 +42,6 @@ import org.hibernate.MappingException;
import org.hibernate.annotations.CacheModeType;
import org.hibernate.annotations.FlushModeType;
import org.hibernate.annotations.QueryHints;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
import org.hibernate.engine.spi.NamedQueryDefinitionBuilder;
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
@ -58,6 +54,9 @@ import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotName
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.logging.Logger;
/**
* Binds {@link NamedQuery}, {@link NamedQueries}, {@link NamedNativeQuery}, {@link NamedNativeQueries},
@ -348,10 +347,13 @@ public class QueryProcessor {
}
else {
AnnotationValue annotationValue = annotation.value( "resultClass" );
NativeSQLQueryRootReturn[] queryRoots;
if ( annotationValue == null ) {
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
// pure native scalar query
queryRoots = new NativeSQLQueryRootReturn[0];
}
NativeSQLQueryRootReturn queryRoots[] = new NativeSQLQueryRootReturn[] {
else {
queryRoots = new NativeSQLQueryRootReturn[] {
new NativeSQLQueryRootReturn(
"alias1",
annotationValue.asString(),
@ -359,6 +361,7 @@ public class QueryProcessor {
LockMode.READ
)
};
}
def = new NamedSQLQueryDefinitionBuilder().setName( name )
.setQuery( query )
.setQueryReturns( queryRoots )

View File

@ -23,18 +23,15 @@
*/
package org.hibernate.metamodel.internal.source.annotations.global;
import javax.persistence.NamedNativeQuery;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexView;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import javax.persistence.NamedNativeQuery;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
@ -43,10 +40,10 @@ import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContextImpl;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import org.jboss.jandex.IndexView;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author Hardy Ferentschik
@ -68,7 +65,7 @@ public class QueryBinderTest extends BaseUnitTestCase {
serviceRegistry.destroy();
}
@Test(expected = NotYetImplementedException.class)
@Test
public void testNoResultClass() {
@NamedNativeQuery(name = "fubar", query = "SELECT * FROM FOO")
class Foo {

View File

@ -20,29 +20,26 @@
*/
package org.hibernate.test.jpa.ql;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.SkipForDialects;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* @author Janario Oliveira
*/
@FailureExpectedWithNewMetamodel
public class NamedNativeQueryTest extends BaseCoreFunctionalTestCase {
private FromEntity createFrom(String name, String lastName) {