I have the following classes:
Code:
@Entity
@IdClass(APK.class)
public class A {
@Id
int id;
}
and
Code:
public class APK implements Serializable{
int id;
}
and
Code:
@Entity
public class B {
@Id
int id;
}
Hibernate 3.2.2 has a problem parsing the following HQL:
Code:
insert into A (id) select b.id from B b
Here is the exception I see:
Code:
Caused by: org.hibernate.QueryException: can only generate ids as part of bulk insert with either sequence or post-insert style generators [insert into A (id) select b.id from com.medq.platform.persistence.ejb.entitymanager.example.B b]
at org.hibernate.hql.ast.HqlSqlWalker.postProcessInsert(HqlSqlWalker.java:622)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.insertStatement(HqlSqlBaseWalker.java:491)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:253)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
The problem seems to be caused by org.hibernate.hql.ast.tree.IntoClause.visitPropertySpecNodes:
Code:
if ( name.equals( persister.getIdentifierPropertyName() ) ) {
explicitIdInsertion = true;
}
getIdentifierPropertyName returns null when IdClass is used, so Hibernate thinks I am not explicitly setting IDs.
This looks like a bug to me. Is it?