HHH-11510 - NativeQuery#iterate throws QuerySyntaxException instead of UnsupportedOperationException
This commit is contained in:
parent
4fcc0d228a
commit
c53939b181
|
@ -369,7 +369,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
|
|||
|
||||
/**
|
||||
* Return the query results as an <tt>Iterator</tt>. If the query
|
||||
* contains multiple results pre row, the results are returned in
|
||||
* contains multiple results per row, the results are returned in
|
||||
* an instance of <tt>Object[]</tt>.<br>
|
||||
* <br>
|
||||
* Entities returned as results are initialized on demand. The first
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Arrays;
|
|||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.FlushModeType;
|
||||
|
@ -239,6 +240,11 @@ public class NativeQueryImpl<T> extends AbstractProducedQuery<T> implements Nati
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterate() {
|
||||
throw new UnsupportedOperationException( "SQL queries do not currently support iteration" );
|
||||
}
|
||||
|
||||
private boolean shouldFlush() {
|
||||
if ( getProducer().isTransactionInProgress() ) {
|
||||
FlushMode effectiveFlushMode = getHibernateFlushMode();
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.sql;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class NativeQueryDoesNotSupportIterationTest
|
||||
extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {TestEntity.class};
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void iterateShouldThrowAnUnsupportedOperationException() {
|
||||
try (Session session = openSession();) {
|
||||
final NativeQuery sqlQuery = session.createNativeQuery(
|
||||
"select * from TEST_ENTITY" );
|
||||
sqlQuery.iterate();
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity")
|
||||
@Table(name = "TEST_ENTITY")
|
||||
public static class TestEntity {
|
||||
|
||||
@Id
|
||||
public Long id;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue