JPAアノテーションを使用して、休止状態に次のエンティティがあります
@Entity
@IdClass(PurchaseCounter.PurchaseCounterPK.class)
@Table(name = "customer_purchases_counter")
public class PurchaseCounter {
public static class PurchaseCounterPK implements Serializable {
Integer customerId;
Integer purchaseId;
public PurchaseCounterPK(Integer customerId, Integer purchaseId) {
this.customerId = customerId;
this.purchaseId = purchaseId;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public Integer getPurchaseId() {
return purchaseId;
}
public void setPurchaseId(Integer purchaseId) {
this.purchaseId = purchaseId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PurchaseCounterPK that = (PurchaseCounterPK) o;
if (customerId != null ? !customerId.equals(that.customerId) : that.customerId != null) return false;
if (purchaseId != null ? !purchaseId.equals(that.purchaseId) : that.purchaseId != null) return false;
return true;
}
@Override
public int hashCode() {
int result = customerId != null ? customerId.hashCode() : 0;
result = 31 * result + (purchaseId != null ? purchaseId.hashCode() : 0);
return result;
}
}
Integer customerId;
Integer purchaseId;
Integer count = 0;
@Id
@Column(name = "customer_id")
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
@Id
@Column(name = "purchase_id")
public Integer getPurchaseId() {
return purchaseId;
}
public void setPurchaseId(Integer purchaseId) {
this.purchaseId = purchaseId;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}
Criteria を使用し、restriction.eq フィルターとして purchaseId と customerId を使用してクエリを実行すると、次のクエリが生成されます。
select this_.customerId as customerId137_0_, this_.purchaseId as purchaseId137_0_, this_.count as count137_0_ from customer_purchases_counter this_ where this_.purchaseId=? and this_.customerId=?
フィールド customerId と purchaseId の名前が @Column を使用して指定した名前に変更されていないため、もちろん間違っています????