私が使用したコードを見つけてください。 HQLクエリは以下を示します。org.hibernate.QueryParameterException:名前付きパラメータ[templateId]が見つかりませんでした
could not locate named parameter [templateId]
しかし、テンプレートIDは私のモデルクラスに存在します。
このタイプのエラーを取得する問題や考えられる理由を解決するために助けてください:
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hql ="from FieldTemplate where templateId= :id";
Query query = session.createQuery(hql);
query.setParameter("templateId", id);
List file=query.list();
tx.commit();
return (FieldTemplate) file.get(0);
モデルファイル
@Entity
@Table(name="EDW_FIELDS")
public class FieldTemplate {
@Id
@Column(name="ID")
@GeneratedValue(strategy=GenerationType.AUTO)
private int Id;
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
@Column(name="TEMPLATE_ID")
private int templateId;
public int getTemplateId() {
return templateId;
}
public void setTemplateId(int templateId) {
this.templateId = templateId;
}
@Column(name="FIELD_NAME")
private String fieldName;
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
@Column(name="DISPLAY_ORDER")
private int displayOrder;
public int getDisplayOrder() {
return displayOrder;
}
public void setDisplayOrder(int displayOrder) {
this.displayOrder = displayOrder;
}
}