Hello,
I have the following PK class:
Code:
/*
* AmountPK.java
*
* Created on Oct 19, 2007, 6:59:36 PM
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.calyonfinancial.cdr.entities;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
*
* @author jumartin
*/
@Embeddable
public class AmountPK implements Serializable, Comparable {
@Column(name = "AMOUNT_CATEGORY_CODE", nullable = false)
private String amountCategoryCode;
@Column(name = "STATEMENT_ID", nullable = false)
private int statementId;
@Column(name = "INTERNAL_REFERENCE", nullable = false)
private int internalReference;
@Column(name = "AMOUNT_TYPE_CODE", nullable = false)
private char amountTypeCode;
public AmountPK() {
System.out.println("AmountPK constructor");
}
public AmountPK(String amountCategoryCode, int statementId, int internalReference, char amountTypeCode) {
this.amountCategoryCode = amountCategoryCode;
this.statementId = statementId;
this.internalReference = internalReference;
this.amountTypeCode = amountTypeCode;
}
public String getAmountCategoryCode() {
return amountCategoryCode;
}
public void setAmountCategoryCode(String amountCategoryCode) {
this.amountCategoryCode = amountCategoryCode;
}
public int getStatementId() {
return statementId;
}
public void setStatementId(int statementId) {
this.statementId = statementId;
}
public int getInternalReference() {
return internalReference;
}
public void setInternalReference(int internalReference) {
this.internalReference = internalReference;
}
public char getAmountTypeCode() {
return amountTypeCode;
}
public void setAmountTypeCode(char amountTypeCode) {
this.amountTypeCode = amountTypeCode;
}
@Override
public int hashCode() {
int hash = 0;
hash += (amountCategoryCode != null ? amountCategoryCode.hashCode() : 0);
hash += (int) statementId;
hash += (int) internalReference;
hash += (int) amountTypeCode;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof AmountPK)) {
return false;
}
AmountPK other = (AmountPK) object;
if ((this.amountCategoryCode == null && other.amountCategoryCode != null) || (this.amountCategoryCode != null && !this.amountCategoryCode.equals(other.amountCategoryCode))) {
return false;
}
if (this.statementId != other.statementId) {
return false;
}
if (this.internalReference != other.internalReference) {
return false;
}
if (this.amountTypeCode != other.amountTypeCode) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.calyonfinancial.cdr.entities.AmountPK[amountCategoryCode=" + amountCategoryCode + ", statementId=" + statementId + ", internalReference=" + internalReference + ", amountTypeCode=" + amountTypeCode + "]";
}
public int compareTo(Object o) {
System.out.println("compareTo");
AmountPK specifiedPk = (AmountPK) o;
int _specified = specifiedPk.internalReference;
int _this = this.internalReference;
if (_this - _specified < 0) {
System.out.println("<0");
return -1;
} else if (_this - _specified > 0) {
System.out.println(">0");
return 1;
} else {
System.out.println("=0");
return 0;
}
}
}
This is the relation/mapping:
Code:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "statement")
@OrderBy("amountPK DESC")
private List<Amount> amountList;
The above annotation will not call the compareTo method...
Can anyone help please?
Julien.