错误是: 错误:org.hibernate.QueryException:只能生成id作为使用序列或插入后样式生成器的批量插入的一部分
HQL:
insert into CategoryProduct (category, product)
select c, p from Category c, Product p
where c.id = 252 and p.id = 554
categoryProduct是一个嵌入了Id的实体:
@EmbeddedId
protected CategoryProductPK categoryProductPK;
提前致谢!
答案 0 :(得分:1)
异常似乎是从org.hibernate.hql.ast.HqlSqlWalker
抛出的:
IdentifierGenerator generator = persister.getIdentifierGenerator();
if ( !supportsIdGenWithBulkInsertion( generator ) ) {
throw new QueryException( "can only generate ids as part of bulk insert with either sequence or post-insert style generators" );
}
并在
做出决定public static boolean supportsIdGenWithBulkInsertion(IdentifierGenerator generator) {
return SequenceGenerator.class.isAssignableFrom( generator.getClass() )
|| PostInsertIdentifierGenerator.class.isAssignableFrom( generator.getClass() );
}
因此,似乎Hibernate希望您使用的生成器是SequenceGenerator
或PostInsertIdentifierGenerator
的子类型。你用的是什么发电机?