我发布此问题是因为所有其他具有相同标题的问题都无法解决我的问题。
我有下表:
CREATE TABLE CONTRACT_DB_AGREEMENT (
AGREEMENT_CODE VARCHAR2(50),
COM_CONTRACT_CODE VARCHAR2(15),
AGREEMENT_TYPE VARCHAR2(20),
EXPIRE_DATE TIMESTAMP(6),
SIGNATORY_USER_NAME NVARCHAR2(150),
SIGNATORY_NAME NVARCHAR2(50),
ORIGINATOR_USER_NAME NVARCHAR2(150),
ORIGINATOR_NAME NVARCHAR2(50),
DATE_CREATED TIMESTAMP(6),
CREATED_BY NVARCHAR2(150),
LAST_UPDATE_DATE TIMESTAMP(6),
LAST_UPDATED_BY NVARCHAR2(150),
CONSTRAINT CONTRACT_DB_AGREEMENT_PK PRIMARY KEY (AGREEMENT_CODE),
CONSTRAINT CONTRACT_DB_AGREEMENT_FK1 FOREIGN KEY(COM_CONTRACT_CODE) REFERENCES CONTRACTS (CONTRACT_CODE)
);
在HBM文件中,我有:
<id name="agreementCode" type="string">
<column name="AGREEMENT_CODE" length="50" />
<generator class="assigned" />
</id>
<property name="agreementType" type="string">
<meta attribute="scope-field">@Length(min = 0, max = 20) private</meta>
<column name="AGREEMENT_TYPE" length="20" />
</property>
<property name="expireDate" type="timestamp">
<column name="EXPIRE_DATE" sql-type="timestamp" />
</property>
<property name="signatoryUserName" type="string">
<meta attribute="scope-field">@Length(min=0, max=150) private</meta>
<column name="SIGNATORY_USER_NAME" length="150" />
</property>
<property name="signatoryName" type="string">
<meta attribute="scope-field">@Length(min=0, max=50) private</meta>
<column name="SIGNATORY_NAME" length="50" />
</property>
<property name="originatorUserName" type="string">
<meta attribute="scope-field">@Length(min=0, max=150) private</meta>
<column name="ORIGINATOR_USER_NAME" length="150" />
</property>
<property name="originatorName" type="string">
<meta attribute="scope-field">@Length(min=0, max=50) private</meta>
<column name="ORIGINATOR_NAME" length="50" />
</property>
<property name="dateCreated" type="timestamp">
<column name="DATE_CREATED" sql-type="timestamp" />
</property>
<property name="createdBy" type="string">
<meta attribute="scope-field">@Length(min=0, max=150) private</meta>
<column name="CREATED_BY" length="150" />
</property>
<property name="lastUpdateDate" type="timestamp">
<column name="LAST_UPDATE_DATE" sql-type="timestamp" />
</property>
<property name="lastUpdatedBy" type="string">
<meta attribute="scope-field">@Length(min=0, max=150) private</meta>
<column name="LAST_UPDATED_BY" length="150" />
</property>
<set name="contractDBAttachments" inverse="true" cascade="save-update">
<key>
<column name="AGREEMENT_CODE" />
</key>
<one-to-many class="ContractDBAttachment" />
</set>
<set name="contractDBNotes" inverse="true" cascade="save-update">
<key>
<column name="AGREEMENT_CODE" />
</key>
<one-to-many class="ContractDBNote" />
</set>
<many-to-one name="contract" class="Contract">
<meta attribute="scope-field">@Length(min = 0, max = 15) private</meta>
<column name="COM_CONTRACT_CODE" length="15"/>
</many-to-one>
我尝试运行这个HQL:
String sql = "SELECT a FROM ContractDBAgreement a WHERE a.comContractCode = ?";
params.add(contractCode);
List<ContractDBAgreement> resultList = DaoManager.getDao(ContractDBAgreement.class).searchBySql(sql, params.toArray());
但是我收到以下错误:
org.hibernate.QueryException: could not resolve property: comContractCode of: com.company.entity.ContractDBAgreement [SELECT a FROM com.company.entity.ContractDBAgreement a WHERE a.comContractCode = ?]
我很感激您的帮助。谢谢!
UPDATE /修改
我更新了字段名称。我试图隐藏我工作的公司名称,并认为我过多地修改了代码。我把它更接近它实际上是什么。相当多,该列被称为“COM_CONTRACT_CODE”,而不仅仅是“CONTRACT_CODE”
答案 0 :(得分:0)
我让这个工作。我必须将<many-to-one>
部分更改为以下内容:
<property name="comContractCode" type="string">
<meta attribute="scope-field">@Length(min = 0, max = 15) private</meta>
<column name="COM_CONTRACT_CODE" length="15"/>
</property>
<many-to-one name="contract" column="COM_CONTRACT_CODE" class="Contract" insert="false" update="false" />