HHH-2692: Correctly reporting type mismatch in select...insert
Conflicts: hibernate-core/src/main/java/org/hibernate/hql/ast/tree/IntoClause.java hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
This commit is contained in:
parent
9304c2b3e9
commit
6ad0d4cfbe
|
@ -128,7 +128,7 @@ public class IntoClause extends HqlSqlWalkerNode implements DisplayableNode {
|
|||
else if ( !areCompatible( types[i], selectTypes[i - parameterCount] ) ) {
|
||||
throw new QueryException(
|
||||
"insertion type [" + types[i] + "] and selection type [" +
|
||||
selectTypes[i] + "] at position " + i + " are not compatible"
|
||||
selectTypes[i - parameterCount] + "] at position " + i + " are not compatible"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,6 +233,28 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
|||
data.cleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleInsertTypeMismatchException() {
|
||||
|
||||
Session s = openSession();
|
||||
try {
|
||||
org.hibernate.Query q = s.createQuery( "insert into Pickup (id, owner, vin) select id, :owner, id from Car" );
|
||||
fail("Parameter type mismatch but no exception thrown");
|
||||
} catch (Throwable throwable) {
|
||||
assertTrue(throwable instanceof QueryException);
|
||||
String m = throwable.getMessage();
|
||||
// insertion type [org.hibernate.type.StringType@21e3cc77] and selection type [org.hibernate.type.LongType@7284aa02] at position 2 are not compatible [insert into Pickup (id, owner, vin) select id, :owner, id from org.hibernate.test.hql.Car]
|
||||
int st = m.indexOf("org.hibernate.type.StringType");
|
||||
int lt = m.indexOf("org.hibernate.type.LongType");
|
||||
assertTrue("type causing error not reported", st > -1);
|
||||
assertTrue("type causing error not reported", lt > -1);
|
||||
assertTrue(lt > st);
|
||||
assertTrue("wrong position of type error reported", m.indexOf("position 2") > -1);
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleNativeSQLInsert() {
|
||||
TestData data = new TestData();
|
||||
|
|
Loading…
Reference in New Issue