do not know how to do it with hsqldb… we have a MSSQL where multiple tables have combined PKs defined.
I added 2 classes which look similar to those we have for those tables with combined PKs.
If you need more information, I would need to create a new project based on SQL Server…
But I do not have the time for that this week.
Actually we got a workaround using JDBCTemplate, but would like to use the saveContext.
In our app the definition looks like this:
for the CompKey
package com.company.ckeydelsampl.entity.key;
import org.springframework.data.util.ProxyUtils;
import javax.persistence.*;
import java.util.Objects;
public class TestTableCompKey {
@Column(name = "PK1", nullable = false, unique = true)
private String PK1;
@Column(name = "PK2", nullable = false, unique = true)
private String PK2;
@Column(name = "PK3", nullable = false, unique = true)
private String PK3;
public String getPK1() {
return PK1;
}
public void setPK1(String PK1) {
this.PK1 = PK1;
}
public String getPK2() {
return PK2;
}
public void setPK2(String PK2) {
this.PK2 = PK2;
}
public String getPK3() {
return PK3;
}
public void setPK3(String PK3) {
this.PK3 = PK3;
}
@Override
public int hashCode() {
return Objects.hash(PK1,PK2,PK3);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || ProxyUtils.getUserClass(this) != ProxyUtils.getUserClass(o)) return false;
TestTableCompKey entity = (TestTableCompKey) o;
return Objects.equals(this.PK1, entity.PK1) &&
Objects.equals(this.PK2, entity.PK2) &&
Objects.equals(this.PK3, entity.PK3);
}
}
/*
package com.jnj.uadwh.entity.key;
@JmixEntity(name = “uadwh_TbluaUpdDistrstockStockJmixCompKey”)
@Embeddable
public class TbluaUpdDistrstockStockJmixCompKey {
@Column(name = “DAYKEY”, nullable = false, unique = true, precision = 38, scale = 0)
private BigDecimal daykey;
@Column(name = "PRODUCTCODE", nullable = false, unique = true, length = 20)
private String productcode;
@Column(name = "UPD_DATE", nullable = false, unique = true)
@Temporal(TemporalType.TIMESTAMP)
private Date updDate;
@Column(name = "WAREHOUSECODE", nullable = false, unique = true, length = 20)
private String warehousecode;
public String getWarehousecode() {
return warehousecode;
}
public void setWarehousecode(String warehousecode) {
this.warehousecode = warehousecode;
}
public Date getUpdDate() {
return updDate;
}
public void setUpdDate(Date updDate) {
this.updDate = updDate;
}
public String getProductcode() {
return productcode;
}
public void setProductcode(String productcode) {
this.productcode = productcode;
}
public BigDecimal getDaykey() {
return daykey;
}
public void setDaykey(BigDecimal daykey) {
this.daykey = daykey;
}
@Override
public int hashCode() {
return Objects.hash(productcode, daykey, warehousecode, updDate);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || ProxyUtils.getUserClass(this) != ProxyUtils.getUserClass(o)) return false;
TbluaUpdDistrstockStockJmixCompKey entity = (TbluaUpdDistrstockStockJmixCompKey) o;
return Objects.equals(this.productcode, entity.productcode) &&
Objects.equals(this.daykey, entity.daykey) &&
Objects.equals(this.warehousecode, entity.warehousecode) &&
Objects.equals(this.updDate, entity.updDate);
}
}
and for the entity.class
package com.company.ckeydelsampl.entity;
import com.company.ckeydelsampl.entity.key.TestTableCompKey;
import io.jmix.core.metamodel.annotation.JmixEntity;
import javax.persistence.*;
@JmixEntity
@Table(name = “TEST_TABLE”)
@Entity
public class TestTable {
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = “PK1”, column = @Column(name = “PK1”)),
@AttributeOverride(name = “PK2”, column = @Column(name = “PK2”)),
@AttributeOverride(name = “PK3”, column = @Column(name = “PK3”)),
})
private TestTableCompKey id;
@Column(name = "COL1")
private String col1;
@Column(name = "COL2")
private String col2;
public String getCol2() {
return col2;
}
public void setCol2(String col2) {
this.col2 = col2;
}
public String getCol1() {
return col1;
}
public void setCol1(String col1) {
this.col1 = col1;
}
public TestTableCompKey getId() {
return id;
}
public void setId(TestTableCompKey id) {
this.id = id;
}
}