请找到我用过的代码。下面的 HQL 查询失败说:
could not locate named parameter [templateId]
但是 templateId 存在于我的模型类中。
请帮助解决问题或出现此类错误的可能原因:
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;
}
}
请帮忙解决我的问题
最佳答案
如果对某人有帮助,也请删除任何 ;如果您的 :param 在查询的最后。
例如,您的查询必须是:
Select * from blah where param = :param
而不是
Select * from blah where param = :param;
(注意最后的;)
关于java - org.hibernate.QueryParameterException : could not locate named parameter [templateId],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915920/