Hi all,
I have seen the issue that I described in the subject, but I think in my case is due to another different cause.
Let's say that I've already created my Database manually (so tables were not created by hibernate). SQL Script (using an Oracle DB) to create one of my tables is like this:
Code:
CREATE TABLE "SOMETHING_TABLE"
(
"COLUMN1" CHAR(10 BYTE) CONSTRAINT "SOMETHING_TABLE_COLUMN1_PK" NOT NULL ENABLE,
"COLUMN2" CHAR(10 BYTE),
"COLUMN3" CHAR(2 BYTE),
)
CREATE UNIQUE INDEX "PK_SOMETHING_TABLE" ON "SOMETHING_TABLE"
(
"COLUMN1", "COLUMN2", "COLUMN3"
)
My hibernate entity is like the following:
Code:
@Entity
@Table(name = "SOMETHING_TABLE")
public class Something_tableImpl {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "COLUMN1")
private String column1 = null;
@Id
@Column(name = "COLUMN2")
private String column2 = null;
@Id
@Column(name = "COLUMN3")
private String column3 = null;
@Column(name = "COLUMN4")
private String column4 = null;
public String getColumn1() {
return column1;
}
public void setColumn1(String column1) {
this.column1 = column1;
}
public String getColumn2() {
return column2;
}
public void setColumn2(String column2) {
this.column2 = column2;
}
public String getColumn3() {
return column3;
}
public void setColumn3(String column3) {
this.column3 = column3;
}
public String getColumn4() {
return column4;
}
public void setColumn4(String column4) {
this.column4 = column4;
}
}
And the hibernate query is like the following:
Code:
public Something_table GetSomethingFrom(String column1, String column2, String column3) {
Criteria queryCriteria = myDAO.getCriteria(Something_tableImpl.class);
queryCriteria.add(Restrictions.eq("column1", column1));
if (StringUtils.isNotBlank(column2)) {
queryCriteria.add(Restrictions.eq("column2", column2));
}
if (StringUtils.isNotBlank(column3)) {
queryCriteria.add(Restrictions.eq("column3", column3));
}
List < Something_table > somethingTableList = queryCriteria.list();
if (!somethingTableList.isEmpty()) {
return somethingTableList.get(0);
}
return null;
}
Let's say that I've already inserted one row in the DB where COLUMN2 and COLUMN3 are NULL (which are part of the index):
Code:
INSERT INTO SOMETHING_TABLE (COLUMN1,COLUMN2,COLUMN3) VALUES ('00011Z66',NULL,NULL);
Whenever I try to get that row that I just inserted, using the above hibernate query, I get a list with one element which is NULL.
If I try to get the same row but directly in Oracle, using the query that underlying was generated by hibernate, then I'm able to get that row that was inserted without problems.
So my question is: Why hibernate is not able to get that row that was inserted?