我尝试在Hibernate 4.3.6 / 4.3.7
中使用下面的insert语句执行批量插入INSERT INTO TransAttrDO (
custCode,
partNo,
custAttrType,
qtyUnit,
createServer
)
SELECT
DISTINCT pp.vendorCode,
pp.partNo,
'PT',
pp.qtyUnit,
'myhost'
FROM PalletPartInfoDO pp
WHERE pp.orderNo = 'SI-HKG-00000001'
我在下面得到了例外。
15:41:22,542 ERROR ErrorCounter:78 - <AST>:8:32: unexpected AST node: DISTINCT
15:41:22,542 ERROR ErrorCounter:73 - <AST>:8:32: unexpected AST node: DISTINCT
<AST>:8:32: unexpected AST node: DISTINCT
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.selectColumn(SqlGeneratorBase.java:1975)
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.selectClause(SqlGeneratorBase.java:544)
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.selectStatement(SqlGeneratorBase.java:186)
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.insertStatement(SqlGeneratorBase.java:440)
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.statement(SqlGeneratorBase.java:153)
at org.hibernate.hql.internal.ast.exec.BasicExecutor.<init>(BasicExecutor.java:63)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.buildAppropriateStatementExecutor(QueryTranslatorImpl.java:580)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:222)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
当我删除DISTINCT
关键字时,它会成功插入记录。如果我执行带有DISTINCT
而没有插入的select语句,它可以正常工作。
有人可以帮忙吗?