我有一个我无法解决的问题。
Hibernate显示了这一点:
Parameter targetDate does not exist as a named parameter in [delete from com.inetpsa.stb.model.Journal t where t.date < :targetDate]
targetDate设置为:
public int purgeOrSave(String hql, Date targetDate) {
Query query = getSession().createQuery(hql);
query.setDate("targetDate", targetDate);
return query.executeUpdate();
}
hql是一个包含要执行的查询的字符串:“从com.inetpsa.stb.model.Journal t中删除,其中t.date
我的实体定义明确。我试图隐藏实体的全限定名称,如下所示:
delete from Journal t where t.date < :targetDate
结果是休眠状态告诉我日记未映射...
任何想法 ?
PS:这是日记的代码:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.inetpsa.stb.model" default-lazy="false">
<class name="Journal" table="STBQTJEV">
<id name="id" type="java.lang.Long" column="JEV_ID">
<generator class="native">
<param name="sequence">STBQXJEV</param>
</generator>
</id>
<property name="uuid" column="JEV_UUID" type="java.lang.String"/>
<property name="canal" column="CAV_CODE" type="java.lang.String"/>
<property name="commandeId" column="CMD_CODE" type="java.lang.String"/>
<property name="contratId" column="CNT_CODE" type="java.lang.String"/>
<property name="contratClient" column="CNT_CONTRAT_CLIENT" type="java.lang.String"/>
<property name="vin" column="VCL_VIN" type="java.lang.String"/>
<property name="clientCode" column="CLT_CODE" type="java.lang.String"/>
<property name="clientMaile" column="CLT_MAIL" type="java.lang.String"/>
<property name="evenementCode" column="EVN_CODE" type="java.lang.String"/>
<property name="offer" column="JEV_OFFER" type="java.lang.String"/>
<property name="produits" column="JEV_PDT" type="java.lang.String"/>
<property name="source" column="JEV_SOURCE" type="java.lang.String"/>
<property name="step" column="JEV_STEP" type="java.lang.String"/>
<property name="statut" column="JEV_STATUT" type="java.lang.String"/>
<property name="commentaire" column="JEV_COM" type="java.lang.String"/>
<property name="detail" column="JEV_DETAIL" type="java.lang.String"/>
<property name="date" column="JEV_DATE" type="java.util.Date"/>
<property name="dateDebut" column="JEV_DATE_DEBU" type="java.sql.Timestamp"/>
<property name="dateFin" column="JEV_DATE_FIN" type="java.sql.Timestamp"/>
</class>
</hibernate-mapping>
最佳答案
采用
query.setParameter(“ targetDate”,targetDate)
代替
query.setDate(“ targetDate”,targetDate)`