我的数据库Employee和EmployeeAssets中有两个表。 EmployeeAssets表保存有关每个员工持有的资产的信息。这些表的模式如下:
//Table Employee
int code (Primary Key)
String name
String address
//Table EmployeeAssets
int rowId (Primary Key, Auto Increment)
int employeeCode (Foreign key, code of Employee table)
String assetCode
我正在使用hibernate 4.x / MySQL来访问这些表。我已经定义了JAVA类来将每个表映射到实体类Employee和EmployeeAssets。现在,我想报告每个员工的姓名和他持有的资产清单。所以我创建了一个这样的java类:
class Report {
public String employeeName;
@OneToMany(cascade= CascadeType.ALL, mappedBy="employeeName")
@JoinColumn(name="assetCode")
public Set<String> assetCodes;
};
我的hibernate查询如下:
session.createQuery("select e.name as employeeName, a.assetCode as assetCode from Employee e, EmployeeAssets a where e.code = a.employeeCode").setResultTransformer(Transformers.aliasToBean(Report.class)).list()
但是上面的查询不起作用,我得到一个例外:
org.hibernate.PropertyNotFoundException: Could not find setter for assetCode on class com.test.model.impl.Report
我确信通过休眠这应该是非常可能的,但我无法弄清楚如何。任何帮助/建议都非常感谢。提前谢谢。