-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: compareTo of Comparable not being called
PostPosted: Wed Oct 24, 2007 10:16 am 
Newbie

Joined: Thu Apr 05, 2007 5:57 am
Posts: 10
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.