我有Hibernate / java代码,我正在尝试修改它以添加对另一个类的引用。我的大部分项目都是由承包商编写的,所以我不熟悉如何编写 Hibernate 部分。我现在在其他一些堆栈流问题中看到了一个错误,但它们似乎不适用于我的特定情况。
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for workbook_config_id in class gov.nrel.nbc.spreadsheet.dto.WorkbookData
我有两个对象,WorkbookData和WorkbookConfig。一个 WorkbookData 有一个且只有一个 WorkbookConfig。
以下片段应涵盖相关代码:
工作簿数据.java
package gov.nrel.nbc.spreadsheet.dto;
import java.io.Serializable;
...
public class WorkbookData implements Serializable {
private static final long serialVersionUID = -2765666207168226677L;
private long workbook_id;
private WorkbookFileData workbook_file_id;
private WorkbookConfig workbook_config_id;
...
/**
* @return the workbook_config_id
*/
public WorkbookConfig getWorkbook_config_id() {
return workbook_config_id;
}
/**
* @param workbook_config_id the workbook_config_id to set
*/
public void setWorkbook_config_id(WorkbookConfig workbook_config_id) {
this.workbook_config_id = workbook_config_id;
}
WorkbookConfig.java
package gov.nrel.nbc.spreadsheet.dto;
import gov.nrel.nbc.spreadsheet.dto.WorkbookFileData;
import gov.nrel.nbc.spreadsheet.dto.SheetConfig;
...
public class WorkbookConfig implements Serializable {
private static final long serialVersionUID = 8789432250514085496L;
private String config_name;
private String synonym;
private long workbook_config_id;
...
/**
* @param workbook_config_id the workbook_config_id to set
*/
public void setWorkbook_config_id(long workbook_config_id) {
this.workbook_config_id = workbook_config_id;
}
/**
* @return the workbook_config_id
*/
public long getWorkbook_config_id() {
return workbook_config_id;
}
工作簿数据.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="gov.nrel.nbc.spreadsheet.dto.WorkbookData" table="workbook_data" lazy="false">
<id name="workbook_id"
column="workbook_id">
<generator class="increment"/>
</id>
<many-to-one name="workbook_file_id"
class="gov.nrel.nbc.spreadsheet.dto.WorkbookFileData"
column="workbook_file_id"
lazy="false"
not-null="false"/>
<many-to-one name="workbook_config_id"
class="gov.nrel.nbc.spreadsheet.dto.WorkbookConfig"
column="workbook_config_id"
not-null="false"/>
...
WorkbookConfig.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="gov.nrel.nbc.spreadsheet.dto.WorkbookConfig" table="workbook_config" lazy="false">
<id
name="workbook_config_id"
column="workbook_config_id">
<generator
class="increment"/>
</id>
<property
name="config_name"
column="config_name"
not-null="true"
lazy="false"/>
<property
name="synonym"
column="synonym"
not-null="true"
lazy="false"/>
WorkbookData 中workbook_config_id 的getter 是getWorkbook_config_id()。所以我不明白为什么我会收到错误。任何人都可以看到这个问题吗?