0
我想知道爲什麼我有不同的結果Hibernait查詢和SQL?我有錯誤的映射? Java和hibernate沒有例外。在這種情況下,我使用Oracle 11數據庫和hibernate 3.5。Hibernate有返回零結果但本地sql返回不同
我的下一個休眠實體:
@Table(name = "pat_otb_registry")
public class OtbEntity implements Comparable<OtbEntity> {
@Column(name = "legal_address_region")
private BigDecimal legalAddressRegion;
@Column(name = "declarant")
private String declarant;
@Column(name = "registry_cert_number")
private String registryCertNumber;
@Column(name = "decision_to_grant_date")
private Date decisionToGrantDate;
@Column(name = "competent_authority")
private BigDecimal competentAuthority;
@Column(name = "expiry_date")
private Date expiryDate;
@Column(name = "decision_to_grant_number")
private String decisionToGrantNumber;
@Column(name = "decision_to_cancel_number")
private String decisionToCancelNumber;
@Column(name = "decision_to_exclude_number")
private String decisionToExcludeNumber;
@Column(name = "certification_authority")
private String certificationAuthority;
@Column(name = "appraisee")
private String appraisee;
@Column(name = "date_of_end_stage")
private Date dateOfEndStage;
@Column(name = "certification_field")
private String certificationField;
@Column(name = "validity_years")
private BigDecimal validityYears;
@Column(name = "decision_to_extend_number")
private String decisionToExtendNumber;
@Column(name = "issue_date")
private Date issueDate;
@Column(name = "reason")
private String reason;
@Column(name = "decision_to_cancel_date")
private Date decisionToCancelDate;
@Column(name = "decision_to_exclude_date")
private Date decisionToExcludeDate;
@Column(name = "decision_to_extend_date")
private Date decisionToExtendDate;
@Column(name = "extended_to_date")
private Date extendedToDate;
@Column(name = "oa_registry_number")
private String oaRegistryNumber;
@Column(name = "grounds_for_issue")
private String groundsForIssue;
@Column(name = "doc_num")
private String docNum;
// then getters and setters....
}
SQL表:
CREATE TABLE pat_otb_registry (
legal_address_region number(10,0) NULL,
declarant nvarchar2(2000) NOT NULL,
registry_cert_number nvarchar2(2000) NOT NULL,
decision_to_grant_date date NULL,
competent_authority smallint NOT NULL,
expiry_date date NULL,
decision_to_grant_number nvarchar2(2000) NULL,
decision_to_cancel_number nvarchar2(2000) NULL,
decision_to_exclude_number nvarchar2(2000) NULL,
certification_authority nvarchar2(2000) NOT NULL,
appraisee varchar2(2000) NOT NULL,
date_of_end_stage date NULL,
certification_field nvarchar2(2000) NULL,
validity_years integer NULL,
decision_to_extend_number nvarchar2(2000) NULL,
issue_date date NULL,
reason nvarchar2(2000) NULL,
decision_to_cancel_date date NULL,
decision_to_exclude_date date NULL,
decision_to_extend_date date NULL,
extended_to_date date NULL,
oa_registry_number nvarchar2(2000) NULL,
grounds_for_issue nvarchar2(2000) NULL,
doc_num nvarchar2(2000) NULL,
CONSTRAINT pat_otb_registry_pk PRIMARY KEY (registry_cert_number)
) ;
Hibernate查詢:
getEntityManager().createQuery("SELECT o FROM " + getEntityName() + " o").getResultList()
SQL查詢:
getEntityManager().createNativeQuery("select * from pat_otb_registry")
除此之外,我沒有看到你的@Id註釋的主鍵它看起來對我好。我沒有耐心檢查所有列名,但我認爲如果命名錯誤,它應該在部署過程中發出抱怨。 –
你原生SQL查詢和休眠請求的一些例子肯定有助於理解問題 – whitesite
直覺告訴我,它將與主鍵使用NVARCHAR2列的選擇/原因有關。涉及的所有相關字符集是什麼? –