I wanted to know why I have different results hibernait query and sql? Have I wrong mapping? Java an hibernate hasn't an exceptions. I use in this case the Oracle 11 database and hibernate 3.5.
I have the next hibernate entity:
@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....
}
The SQL Table:
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)
) ;
the hibernate query:
getEntityManager().createQuery("SELECT o FROM " + getEntityName() + " o").getResultList()
SQL query:
getEntityManager().createNativeQuery("select * from pat_otb_registry")
I found a bug. I have not worked properly EntityManager - getEntityManager()