We are currently migrating from Hibernate 5.6 to Hibernate 6.2. We have a composite key defined using the @IdClass strategy as follows:
public class DuesReportCorrelationId implements Serializable {
private static final long serialVersionUID = 1L;
private String annex;
private String itemCeCode;
public DuesReportCorrelationId() {
}
public DuesReportCorrelationId(String annex, String itemCeCode) {
this.annex = annex;
this.itemCeCode = itemCeCode;
}
// Getters and Setters
public String getAnnex() {
return annex;
}
public void setAnnex(String annex) {
this.annex = annex;
}
public String getItemCeCode() {
return itemCeCode;
}
public void setItemCeCode(String itemCeCode) {
this.itemCeCode = itemCeCode;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DuesReportCorrelationId that = (DuesReportCorrelationId) o;
return Objects.equals(annex, that.annex) && Objects.equals(itemCeCode, that.itemCeCode);
}
@Override
public int hashCode() {
return Objects.hash(annex, itemCeCode);
}
}
@Entity
@Table(name = "DUES_REPORT_CORRELATION")
@IdClass(DuesReportCorrelationId.class)
public class DuesReportCorrelation {
@Id
@Column(name = "ANNEX", nullable = false)
@NotNull
@Size(min = 1, max = 2)
private String annex;
@Column(name = "REF_CODE", nullable = false)
@NotNull
@Size(min = 1, max = 4)
private String refCode;
@Column(name = "ITEM_TYPE", nullable = false)
@NotNull
@Size(min = 1, max = 100)
private String itemType;
@Id
@Column(name = "ITEM_CE_CODE", nullable = false)
@NotNull
@Size(min = 1, max = 12)
private String itemCeCode;
public DuesReportCorrelation() {
}
public DuesReportCorrelation(String annex, String refCode, String itemType, String itemCeCode) {
this.annex = annex;
this.refCode = refCode;
this.itemType = itemType;
this.itemCeCode = itemCeCode;
}
public String getAnnex() {
return annex;
}
public void setAnnex(String annex) {
this.annex = annex;
}
public String getRefCode() {
return refCode;
}
public void setRefCode(String refCode) {
this.refCode = refCode;
}
public String getItemType() {
return itemType;
}
public void setItemType(String itemType) {
this.itemType = itemType;
}
public String getItemCeCode() {
return itemCeCode;
}
public void setItemCeCode(String itemCeCode) {
this.itemCeCode = itemCeCode;
}
}
The query constructed in Hibernate 5 is:
select
duesreport0_.ANNEX as annex1_27_,
duesreport0_.ITEM_CE_CODE as item_ce_2_27_,
duesreport0_.REF_CODE as ref_code3_27_,
duesreport0_.ITEM_TYPE as item_typ4_27_
from
DUES_REPORT_CORRELATION duesreport0_
where
(
duesreport0_.ANNEX, duesreport0_.ITEM_CE_CODE
) in (
select
distinct duesreport1_.ANNEX,
duesreport1_.ITEM_CE_CODE
from
DUES_REPORT_CORRELATION duesreport1_
where
1=1
)
order by
duesreport0_.ANNEX,
duesreport0_.ITEM_CE_CODE limit ?
as opposed to the following Hibernate 6 version which encapsulates the composite key fields within parentheses:
select d1_0.ANNEX,d1_0.ITEM_CE_CODE,d1_0.ITEM_TYPE,d1_0.REF_CODE from DUES_REPORT_CORRELATION d1_0
where (d1_0.ANNEX,d1_0.ITEM_CE_CODE) in(select distinct (d2_0.ANNEX,d2_0.ITEM_CE_CODE)
from DUES_REPORT_CORRELATION d2_0 where 1=1)
order by d1_0.ANNEX,d1_0.ITEM_CE_CODE offset ? rows fetch first ? rows only
causing an H2 exception:
org.h2.jdbc.JdbcSQLSyntaxErrorException: Column count does not match
However, the query constructed is syntactically incorrect also in Oracle:
ORA-00920: invalid relational operator
I tried switching to the Embeddable strategy but the problem persists.
Could you please offer some insight?
Thank you in advance.