我需要将以下SQL查询编写为HQL
insert into aab_appl_training tr (tr.training_id,tr.appl_id,tr.course_name,tr.completed_dt,tr.cert_by,tr.cert_num,tr.train_comp)
select aab_appl_training_seq.nextval,'10071',tr.course_name,tr.completed_dt,tr.cert_by,tr.cert_num,tr.train_comp
from aab_appl_training tr
where tr.appl_id=10018
我的困境在于我的映射文件中我将AABApplication映射为aab_appl_training表的多对一
<hibernate-mapping>
<class name="org.sae.model.aab.AABTraining" table="AAB_APPL_TRAINING" schema="CMS">
<id name="trainingId" type="java.lang.Long">
<column name="TRAINING_ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">AAB_APPL_TRAINING_SEQ</param></generator>
</id>
<many-to-one name="AABApplication" class="org.sae.model.aab.AABApplication" fetch="select">
<column name="APPL_ID" precision="10" scale="0" not-null="true" />
</many-to-one>
我为此编写的HQL是
String hql="insert into AABTraining (tr.applId,tr.courseName,tr.completedDt,tr.certBy,tr.certNum,tr.trainComp)"+" "+"select :new_appl,tr.courseName,tr.completedDt,tr.certBy,tr.certNum,tr.trainComp"+" "+
"from AABTraining tr "+" "+"where tr.applId=:orig_appl" ;
然而,对于这个我得到了
的例外[ERROR][2014-06-02 15:28:03,082] [] [AAB] [PARSER] [] <AST>:1:28: unexpected AST node: .[ERROR][2014-06-02 15:28:03,083] [] [AAB] [AABRepositoryImpl] [] org.hibernate.QueryException: could not resolve property: of:org.sae.model.aab.AABTraining [insert into AABTraining (tr.applId,tr.courseName,tr.completedDt,tr.certBy,tr.certNum,tr.trainComp) select :new_appl,tr.courseName,tr.completedDt,tr.certBy,tr.certNum,tr.trainComp from org.sae.model.aab.AABTraining tr where tr.applId=:orig_appl]
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1282)
请帮我写相同的正确查询。 感谢
答案 0 :(得分:1)
您可以在HQL中使用INSERT/SELECT,但您的查询存在一些问题: