gpt4 book ai didi

hibernate - org.hibernate.QueryException - 无法解析属性

转载 作者:行者123 更新时间:2023-12-02 07:02:38 26 4
gpt4 key购买 nike

我正在尝试使用 Hibernate 连接到数据库。当前表格具有以下布局:

(field1, field2, field3, optional1, optional2...)

其中 field1、field2、field3 都是外键,它们一起组成一个组合键。

我有以下类(class):

@Entity
@Table(name = "db_table_mainRecords")
public class MainRecord implements Serializable{
@EmbeddedId
private MainRecordKey lqk;
@Transient
private String field1;
@Transient
private int field2;
@Transient
private int field3;
@Column(name = "optional_1")
private double optional1;
@Column(name = "optional_2")
private double optional2;

....
// Getters and setters for all fields, including fields within MainClassKey
....
}

伴随着它:

@Embeddable
@Table(name = "db_table_mainRecords")
public class MainRecordKey implements Serializable{
@Column(name = "field1")
private String field_1;
@Column(name = "field_2")
private int field2;
@Column(name = "field_3")
private int field3;
}

我收到以下错误:

org.hibernate.QueryException - could not resolve property: field3 of: path.MainRecord at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67)

这是我的 Bo/dao 代码:

public List<MainRecord> getMainRecords(int e){
Criterion crit1 = Restrictions.eq("field3", e);
ArrayList<MainRecord> list = (ArrayList<MainRecord>) dao.getMainRecords(crit1);
}


public List<MainRecord> getMainRecords(Criterion criteria){
if(criteria == null)
return new ArrayList<MainReocrd>();
return (List<MainRecord>) getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(MainRecord.class).add(criteria));
}

最佳答案

尝试将映射文件 MainRecord 中的所有 int 更改为 Integer 并将 double 更改为 Double MainRecordKey

更新试试这个:

Restrictions.eq("lqk.field3", e);

关于hibernate - org.hibernate.QueryException - 无法解析属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17859707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com