-->
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.  [ 4 posts ] 
Author Message
 Post subject: TreeSet contains() read failure
PostPosted: Mon Sep 12, 2005 4:47 pm 
Newbie

Joined: Thu Feb 17, 2005 10:27 am
Posts: 8
Hibernate version:
2.1

Name and version of the database you are using:
Oracle 9i


I am having a problem with the contains method on a Set mapped in hibernate. The collection is defined in the DiscountProgramAccount bean as customerContacts. The type of each item in the collection is CustomerAccountContact. All relevant code, including mappings, is provided below.


Mappings

DiscountProgramAccount

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="com.sas.edu.educentral.edusa.beans.DiscountProgramAccount" table="DISC_PGM_ACCT" dynamic-insert="true" dynamic-update="true" optimistic-lock="version">

<!-- ID generated by custom class (String). -->
<id name="accountNumber" type="java.lang.String" column="ACCT_NBR" unsaved-value="null">
<generator class="com.sas.edu.educentral.system.EduCentralIdentifierGeneratorFive"/>
</id>

<version type="integer" name="version" column="VERSION" access="field"/>

<property name="discountProgramID" type="string" column="DISC_PGM_ID"/>
<many-to-one name="discountProgram" column="DISC_PGM_ID" insert="false" update="false" class="com.sas.edu.educentral.edusa.beans.DiscountProgram" cascade="none"/>

<set name="sasContacts" sort="natural" inverse="true" lazy="true" batch-size="50" cascade="all-delete-orphan">
<key column="ACCT_NBR"/>
<one-to-many class="com.sas.edu.educentral.edusa.beans.SASAccountContact"/>
</set>

<set name="customerContacts" sort="natural" inverse="true" lazy="true" batch-size="50" cascade="all-delete-orphan">
<key column="ACCT_NBR"/>
<one-to-many class="com.sas.edu.educentral.edusa.beans.CustomerAccountContact"/>
</set>

<set name="programOffers" sort="natural" inverse="true" lazy="true" batch-size="50" cascade="save-update">
<key column="ACCT_NBR"/>
<one-to-many class="com.sas.edu.educentral.edusa.beans.ProgramOffer"/>
</set>

<property name="customerNumber" type="string" column="CUSTOMER_NUMBER" access="field"/>
<property name="customerName" type="string" column="CUSTOMER_NAME"/>

<property name="billingCustomerNumber" type="string" column="BILLING_CUSTOMER_NUMBER"/>
<property name="billingPersonID" type="string" column="BILLING_PERSON_ID"/>
<property name="billingAddressID" type="string" column="BILLING_ADDR_ID"/>

<property name="inactive" type="string" column="INACTIVE"/>
<property name="adminRegisterOnly" type="string" column="ADMIN_REGISTER_ONLY"/>

<property name="created" type="calendar" column="CREATED"/>
<property name="createdBy" type="string" column="CREATEDBY"/>
<property name="lastUpdated" type="calendar" column="LASTUPDATED"/>
<property name="lastUpdatedBy" type="string" column="LASTUPDATEDBY"/>

</class>

</hibernate-mapping>


CustomerAccountContact

<hibernate-mapping>

<class name="com.sas.edu.educentral.edusa.beans.CustomerAccountContact" table="CUST_ACCT_CNTCT" dynamic-insert="true" dynamic-update="true">

<composite-id>
<key-property name="accountNumber" type="string" column="ACCT_NBR" />
<key-property name="personID" type="string" column="PERSON_ID" access="field" />
</composite-id>

<version type="java.util.Calendar" name="lastUpdated" column="LASTUPDATED" unsaved-value="null"/>

<many-to-one name="account" column="ACCT_NBR" class="com.sas.edu.educentral.edusa.beans.DiscountProgramAccount" insert="false" update="false" cascade="none"/>

<property name="personID" type="string" column="PERSON_ID" insert="false" update="false" access="field"/>
<property name="customerNumber" type="string" column="CUSTOMER_NUMBER"/>

<property name="firstName" type="string" column="FIRST_NAME"/>
<property name="lastName" type="string" column="LAST_NAME"/>
<property name="emailAddress" type="string" column="EMAIL_ADDRESS"/>

<property name="primaryContact" type="string" column="PRIMARY_CONTACT"/>
<property name="allActivityEmail" type="string" column="ALL_ACTIVITY_EMAIL"/>
<property name="inactive" type="string" column="INACTIVE"/>

<property name="addressID" type="string" column="ADDR_ID"/>

</class>

</hibernate-mapping>

End of Mappings



The Problem

The TreeSet does not appear to traverse all elements of the set when given a CustomerAccountContact object not read from Hibernate. If, however, the non-Hibernate object matches the first element traversed in the call to contains(), true is returned. If given a Hibernate-generated object read from the DB, all elements of the TreeSet are traversed until a match is found (or not), resulting in a correct return from contains. This is odd, because the equals method in the CustomerAccountContact bean checks only against the composite key fields, made up of AccountNumber and PersonID. The compareTo method checks the equals method first to ensure that it is consistent with the equals method, and therefore will not cause undefined behavior in the TreeSet. The equals, compareTo, and hashCode methods are as follows:


equals/compareTo/hashCode Methods

/**
* Method required for implementation of Comparable interface. Primary contacts are
* always listed first (less than). If the comparison is between two contacts that
* are not primary, then the comparison is on name with precedence last name -> first
* name. A null pointer exception is thrown if the personID fields of each object are
* not populated with valid Strings.
* @author ryalbe
* @param specified object to be compared with this one
* @return 0 if equal, less than 0 if this object is 'less' than that specified, and greater than zero if this object is 'greater' than that specified.
*/
public int compareTo(Object o) {
if( o != null ) {
log.debug( "Comparing this (" + this.getAccountNumber() + ", " + this.getPersonID() + ", " + this.hashCode() + ") to o (" + ((CustomerAccountContact)o).getAccountNumber() + ", " + ((CustomerAccountContact)o).getPersonID() + ", " + ((CustomerAccountContact)o).hashCode() + ")..." );
}
else {
log.debug( "Comparing this to o, but o is null..." );
}

if( o == null ) { throw new NullPointerException( "Object o is null in CustomerAccountContact compareTo method." ); }
if( this.equals(o) ) {
log.debug( "CompareTo returning 0..." );
return 0;
}

int lastNameCompare = 0;

// run last name check
if( this.getLastName() != null || ((CustomerAccountContact)o).getLastName() != null ) {
if( this.getLastName() != null && ((CustomerAccountContact)o).getLastName() == null ) {
lastNameCompare = -1; // put this ahead of the null
}
else if( this.getLastName() == null && ((CustomerAccountContact)o).getLastName() != null ) {
lastNameCompare = 1; // put this behind not null value
}
else {
lastNameCompare = this.getLastName().compareTo( ((CustomerAccountContact)o).getLastName() );
}
}

// run primary check (primary contact takes order priority over last name)
if( lastNameCompare != 0 ) {
if( this.primaryContact != null && this.primaryContact.toUpperCase().equals("Y") ) {
log.debug( "CompareTo returning -1..." );
return -1; // this is primary contact--move it to front
}
else if( ((CustomerAccountContact)o).getPrimaryContact() != null && ((CustomerAccountContact)o).getPrimaryContact().toUpperCase().equals("Y") ) {
log.debug( "CompareTo returning 1..." );
return 1; // o is primary contact--move it to front
}
}

log.debug( "CompareTo returning " + lastNameCompare + "..." );

return lastNameCompare; // return last name comparison result
}


/**
* Overrides the default object equals method.
* @author ryalbe
*/
public boolean equals( Object o ) {
if( o != null ) {
log.debug( "Performing equals check on this (" + this.getAccountNumber() + ", " + this.getPersonID() + ", " + this.hashCode() + ") to o (" + ((CustomerAccountContact)o).getAccountNumber() + ", " + ((CustomerAccountContact)o).getPersonID() + ", " + ((CustomerAccountContact)o).hashCode() + ")..." );
}
else {
log.debug( "Performing equals check on this to o, but o is null..." );
}

if( this == o ) { return true; }
if( o == null ) { return false; }
if( !(o instanceof CustomerAccountContact) ) { return false; }
if( this.getPersonID() == null ) { return false; }


if( this.getAccountNumber() == null && ((CustomerAccountContact)o).getAccountNumber() == null || this.getAccountNumber().equals(((CustomerAccountContact)o).getAccountNumber()) ) {
log.debug( "Account number for this (" + this.getAccountNumber() + ") and o (" + ((CustomerAccountContact)o).getAccountNumber() + ") are equal..." );
}
else {
log.debug( "Account number for this (" + this.getAccountNumber() + ") and o (" + ((CustomerAccountContact)o).getAccountNumber() + ") are NOT equal..." );
}

if( this.getPersonID().equals(((CustomerAccountContact)o).getPersonID()) ) {
log.debug( "PersonID for this (" + this.getPersonID() + ") and o (" + ((CustomerAccountContact)o).getPersonID() + ") are equal..." );
}
else {
log.debug( "PersonID for this (" + this.getPersonID() + ") and o (" + ((CustomerAccountContact)o).getPersonID() + ") are NOT equal..." );
}

if( (this.getAccountNumber() == null && ((CustomerAccountContact)o).getAccountNumber() == null || this.getAccountNumber().equals(((CustomerAccountContact)o).getAccountNumber())) && this.getPersonID().equals(((CustomerAccountContact)o).getPersonID()) ) {
log.debug( "This (" + this.getAccountNumber() + ", " + this.getPersonID() + ", " + this.hashCode() + ") and o (" + ((CustomerAccountContact)o).getAccountNumber() + ", " + ((CustomerAccountContact)o).getPersonID() + ", " + ((CustomerAccountContact)o).hashCode() + ") are equal..." );
}
else {
log.debug( "This (" + this.getAccountNumber() + ", " + this.getPersonID() + ", " + this.hashCode() + ") and o (" + ((CustomerAccountContact)o).getAccountNumber() + ", " + ((CustomerAccountContact)o).getPersonID() + ", " + ((CustomerAccountContact)o).hashCode() + ") are NOT equal..." );
}


return ( (this.getAccountNumber() == null && ((CustomerAccountContact)o).getAccountNumber() == null || this.getAccountNumber().equals(((CustomerAccountContact)o).getAccountNumber())) && this.getPersonID().equals(((CustomerAccountContact)o).getPersonID()) );
}

/**
* Overrides the default object hashcode method.
*/
public int hashCode() {
if( this.getAccountNumber() != null && this.getPersonID() != null ) {
return this.getAccountNumber().hashCode() + this.getPersonID().hashCode();
}

return 0; // hashcode for all nonvalid composite ids
}

End equals/compareTo/hashCode Methods



As you can see, in an effort to diagnose the cause of the problem, there is quite a bit of debug code in these methods. Below I am including code that tests these methods along with output
that demonstrates the issue.


Test Code

CustomerAccountContact cacNew = new CustomerAccountContact(discPgmAcct.getAccountNumber(), contact.getPartyId().toString());
CustomerAccountContact cacDB = new CustomerAccountContactManager().getCustomerAccountContact( discPgmAcct.getAccountNumber(), contact.getPartyId().toString() );

System.out.println( "\n\n" );

if( discPgmAcct.getCustomerContacts() != null ) {
if( discPgmAcct.getCustomerContacts().contains(cacNew) ) {
System.out.println( "discPgmAcct.getCustomerContacts() contains cacNew (" + cacNew.getAccountNumber() + ", " + cacNew.getPersonID() + ", " + cacNew.hashCode() + ")..." );
} else {
System.out.println( "discPgmAcct.getCustomerContacts() does not contain cacNew (" + cacNew.getAccountNumber() + ", " + cacNew.getPersonID() + ", " + cacNew.hashCode() + ")..." );
}

System.out.println( "\n\n" );

if( discPgmAcct.getCustomerContacts().contains(cacDB) ) {
System.out.println( "discPgmAcct.getCustomerContacts() contains cacDB (" + cacDB.getAccountNumber() + ", " + cacDB.getPersonID() + ", " + cacDB.hashCode() + ")..." );
} else {
System.out.println( "discPgmAcct.getCustomerContacts() does not contain cacDB (" + cacDB.getAccountNumber() + ", " + cacDB.getPersonID() + ", " + cacDB.hashCode() + ")..." );
}

System.out.println( "\n\n" );


System.out.println( "<<<" );
Iterator i = discPgmAcct.getCustomerContacts().iterator();
CustomerAccountContact hammer = (CustomerAccountContact)i.next();
CustomerAccountContact desikar = (CustomerAccountContact)i.next();

Set hibernateContactSet = new TreeSet();
hibernateContactSet.add( hammer );
hibernateContactSet.add( desikar );
System.out.println( ">>>" );


System.out.println( "\n\n" );

if( hibernateContactSet.contains(cacNew) ) {
System.out.println( "Hibernate contact set contains cacNew (" + cacNew.getAccountNumber() + ", " + cacNew.getPersonID() + ", " + cacNew.hashCode() + ")." );
} else {
System.out.println( "Hibernate contact set does not contain cacNew (" + cacNew.getAccountNumber() + ", " + cacNew.getPersonID() + ", " + cacNew.hashCode() + ")." );
}

System.out.println( "\n\n" );

if( hibernateContactSet.contains(cacDB) ) {
System.out.println( "Hibernate contact set contains cacDB (" + cacDB.getAccountNumber() + ", " + cacDB.getPersonID() + ", " + cacDB.hashCode() + ")." );
} else {
System.out.println( "Hibernate contact set does not contain cacDB (" + cacDB.getAccountNumber() + ", " + cacDB.getPersonID() + ", " + cacDB.hashCode() + ")." );
}
}

System.out.println( "\n\n" );


System.out.println( "<<<" );
Set contacts = new TreeSet();
contacts.add( new CustomerAccountContact(discPgmAcct.getAccountNumber(), "1088291") );
contacts.add( new CustomerAccountContact(discPgmAcct.getAccountNumber(), "772682") );
System.out.println( ">>>" );


System.out.println( "\n" );

if( contacts.contains(cacNew) ) {
System.out.println( "Non-hibernate contact set contains cacNew (" + cacNew.getAccountNumber() + ", " + cacNew.getPersonID() + ", " + cacNew.hashCode() + ")." );
} else {
System.out.println( "Non-hibernate contact set does not contain cacNew (" + cacNew.getAccountNumber() + ", " + cacNew.getPersonID() + ", " + cacNew.hashCode() + ")." );
}

System.out.println( "\n\n" );

if( contacts.contains(cacDB) ) {
System.out.println( "Non-hibernate contact set contains cacDB (" + cacDB.getAccountNumber() + ", " + cacDB.getPersonID() + ", " + cacDB.hashCode() + ")." );
} else {
System.out.println( "Non-hibernate contact set does not contain cacDB (" + cacDB.getAccountNumber() + ", " + cacDB.getPersonID() + ", " + cacDB.hashCode() + ")." );
}

System.out.println( "\n\n" );

End Test Code


Debug Output

16:10:16,141 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,141 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,141 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,141 DEBUG CustomerAccountContact:743 - PersonID for this (772682) and o (1088291) are NOT equal...
16:10:16,141 DEBUG CustomerAccountContact:750 - This (27054, 772682, 1674802568) and o (27054, 1088291, 2013504373) are NOT equal...
16:10:16,141 DEBUG CustomerAccountContact:708 - CompareTo returning 4...

discPgmAcct.getCustomerContacts() does not contain cacNew (27054, 772682, 1674802568)...



16:10:16,156 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,156 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,156 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,156 DEBUG CustomerAccountContact:743 - PersonID for this (772682) and o (1088291) are NOT equal...
16:10:16,156 DEBUG CustomerAccountContact:750 - This (27054, 772682, 1674802568) and o (27054, 1088291, 2013504373) are NOT equal...
16:10:16,156 DEBUG CustomerAccountContact:699 - CompareTo returning -1...

16:10:16,156 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,156 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,156 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,156 DEBUG CustomerAccountContact:740 - PersonID for this (772682) and o (772682) are equal...
16:10:16,172 DEBUG CustomerAccountContact:747 - This (27054, 772682, 1674802568) and o (27054, 772682, 1674802568) are equal...
16:10:16,172 DEBUG CustomerAccountContact:677 - CompareTo returning 0...

discPgmAcct.getCustomerContacts() contains cacDB (27054, 772682, 1674802568)...



16:10:16,172 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,172 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,172 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,172 DEBUG CustomerAccountContact:740 - PersonID for this (772682) and o (772682) are equal...
16:10:16,188 DEBUG CustomerAccountContact:747 - This (27054, 772682, 1674802568) and o (27054, 772682, 1674802568) are equal...
16:10:16,188 DEBUG CustomerAccountContact:677 - CompareTo returning 0...

Hibernate contact set contains cacNew (27054, 772682, 1674802568).



16:10:16,188 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,188 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,188 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,188 DEBUG CustomerAccountContact:740 - PersonID for this (772682) and o (772682) are equal...
16:10:16,188 DEBUG CustomerAccountContact:747 - This (27054, 772682, 1674802568) and o (27054, 772682, 1674802568) are equal...
16:10:16,188 DEBUG CustomerAccountContact:677 - CompareTo returning 0...

Hibernate contact set contains cacDB (27054, 772682, 1674802568).



16:10:16,360 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,360 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,360 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,375 DEBUG CustomerAccountContact:743 - PersonID for this (772682) and o (1088291) are NOT equal...
16:10:16,375 DEBUG CustomerAccountContact:750 - This (27054, 772682, 1674802568) and o (27054, 1088291, 2013504373) are NOT equal...
16:10:16,375 DEBUG CustomerAccountContact:708 - CompareTo returning 4...

16:10:16,375 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,375 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:10:16,375 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,375 DEBUG CustomerAccountContact:740 - PersonID for this (772682) and o (772682) are equal...
16:10:16,375 DEBUG CustomerAccountContact:747 - This (27054, 772682, 1674802568) and o (27054, 772682, 1674802568) are equal...
16:10:16,375 DEBUG CustomerAccountContact:677 - CompareTo returning 0...

Non-hibernate contact set contains cacNew (27054, 772682, 1674802568).



16:10:16,391 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,391 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,391 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,391 DEBUG CustomerAccountContact:743 - PersonID for this (772682) and o (1088291) are NOT equal...
16:10:16,391 DEBUG CustomerAccountContact:750 - This (27054, 772682, 1674802568) and o (27054, 1088291, 2013504373) are NOT equal...
16:10:16,391 DEBUG CustomerAccountContact:699 - CompareTo returning -1...

Non-hibernate contact set does not contain cacDB (27054, 772682, 1674802568).



16:10:16,469 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,469 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:10:16,485 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:10:16,485 DEBUG CustomerAccountContact:743 - PersonID for this (772682) and o (1088291) are NOT equal...
16:10:16,485 DEBUG CustomerAccountContact:750 - This (27054, 772682, 1674802568) and o (27054, 1088291, 2013504373) are NOT equal...
16:10:16,485 DEBUG CustomerAccountContact:708 - CompareTo returning 4...

End Debug Output



If I reverse the order of insert into the hibernateContactSet and place 'vesikar' in ahead of 'hammer', the non-hibernate object read fails against the hibernateContactSet (see below).

Reverse-insert Debug


16:12:07,673 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:12:07,673 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:12:07,673 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:12:07,673 DEBUG CustomerAccountContact:743 - PersonID for this (772682) and o (1088291) are NOT equal...
16:12:07,688 DEBUG CustomerAccountContact:750 - This (27054, 772682, 1674802568) and o (27054, 1088291, 2013504373) are NOT equal...
16:12:07,688 DEBUG CustomerAccountContact:708 - CompareTo returning 4...

Hibernate contact set does not contain cacNew (27054, 772682, 1674802568).



16:12:07,688 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:12:07,688 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 1088291, 2013504373)...
16:12:07,688 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:12:07,688 DEBUG CustomerAccountContact:743 - PersonID for this (772682) and o (1088291) are NOT equal...
16:12:07,688 DEBUG CustomerAccountContact:750 - This (27054, 772682, 1674802568) and o (27054, 1088291, 2013504373) are NOT equal...
16:12:07,688 DEBUG CustomerAccountContact:699 - CompareTo returning -1...

16:12:07,704 DEBUG CustomerAccountContact:669 - Comparing this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:12:07,704 DEBUG CustomerAccountContact:720 - Performing equals check on this (27054, 772682, 1674802568) to o (27054, 772682, 1674802568)...
16:12:07,704 DEBUG CustomerAccountContact:733 - Account number for this (27054) and o (27054) are equal...
16:12:07,704 DEBUG CustomerAccountContact:740 - PersonID for this (772682) and o (772682) are equal...
16:12:07,704 DEBUG CustomerAccountContact:747 - This (27054, 772682, 1674802568) and o (27054, 772682, 1674802568) are equal...
16:12:07,704 DEBUG CustomerAccountContact:677 - CompareTo returning 0...

Hibernate contact set contains cacDB (27054, 772682, 1674802568).

End Reverse-insert Debug


Could someone tell me if this is a failure with the way Hibernate manipulates the set and DB objects, or if this is a failure with my mappings or object equals/compareTo methods? I have tried diagnosing this as a problem with my implementation, but the only constant here is that the TreeSet is not comparing against all objects when the objects in the set are Hibernate-generated and the object given to the contains() method is not or when the TreeSet contains non-hibernate objects and a hibernate object is fed into the contains method. So, I am specifically wondering if this is an issue with the bytecode manipulation that hibernate performs on its mapped objects, or if it is something I have done.

Let me know if you need any other information. PLEASE HELP WITH THIS!

Thanks,

Ryan


Top
 Profile  
 
 Post subject: Re: TreeSet contains() read failure
PostPosted: Mon Sep 12, 2005 5:12 pm 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
ryalbe wrote:
// run primary check (primary contact takes order priority over last name)
if( lastNameCompare != 0 ) {
if( this.primaryContact != null && this.primaryContact.toUpperCase().equals("Y") ) {
log.debug( "CompareTo returning -1..." );
return -1; // this is primary contact--move it to front
}
else if( ((CustomerAccountContact)o).getPrimaryContact() != null && ((CustomerAccountContact)o).getPrimaryContact().toUpperCase().equals("Y") ) {
log.debug( "CompareTo returning 1..." );
return 1; // o is primary contact--move it to front
}
}

log.debug( "CompareTo returning " + lastNameCompare + "..." );

return lastNameCompare; // return last name comparison result
}


I havent tried your test-code, so sorry if I am wrong, but I think in your compareTo method is an error.
The check for the PrimaryContact is wrong as you didnt take the other side into account - or in other words
if you compare a primary contact (or non primary contact) with another one this wont return "0".

Just an idea.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 5:24 pm 
Newbie

Joined: Thu Feb 17, 2005 10:27 am
Posts: 8
That's why the equals check comes first. If equals returns true, the compareTo method doesn't even make the primaryContact check.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 9:44 am 
Newbie

Joined: Thu Feb 17, 2005 10:27 am
Posts: 8
This also appears to be true of HashSet...


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

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.