我正在尝试使用 Hibernate 连接到数据库。
此当前表格具有以下布局:
(field1, field2, field3, optional1, optioanl2...)
其中field1、field2、field3都是外键,共同组成一个复合键。
我有以下课程:
@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 - 无法解析属性:field3 of:org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67)的 path.MainRecord
这是我的博/道代码
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));
}