diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/IntoClause.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/IntoClause.java index 88c81f41e1..b35910dd78 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/IntoClause.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/IntoClause.java @@ -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" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java index efbc5de7aa..d24b6e3075 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java @@ -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();