]
Steve Ebersole closed HHH-1095.
-------------------------------
Closing stale resolved issues
Hibernate takes incorrect HasCode when a lot of CompositeKeys and
Lazy loading is involved
------------------------------------------------------------------------------------------
Key: HHH-1095
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1095
Project: Hibernate Core
Issue Type: Patch
Affects Versions: 3.1 rc2
Environment: Hibernate 3.0.5 and 3.1-cvs
Reporter: Konstantin Ignatyev
Fix For: 3.1 rc3
Attachments: EntityType.java.3.0.5.patch, EntityType.java.3.1.patch,
sup7repro.zip
The problem is that when trying to load the OrderLines collection from an Order, the set
came back as being empty, which it should not have.
It is important to note that Order has a composite primary key composed of order_id and
District. This is encapsulated in an OrderId class. District has a composite primary key
composed of d_id and Warehouse, this is encapsulated in a districtId class. Warehouse has
an integer as it's primary key.
OrderLine has a composite primary key that is composed of Order and ol_number (which is a
short). This is encapsulated in an OrderLineId class.
Each of the custom classes that represents a composite primarey key has hash() and
equals() overridden.
The problem we seem to be running into is that when Hibernate loads the collection for
this object it first runs through and creates an emply collection in the
CollectionLoadingContext. It does this with the OrderId it gets from the
PersistantColleciton, which is already fully loaded and has an actual District rather that
a proxied District.
Then when we process our query results we get back into getLoadingCollection with the
OrderId we read from the ResultSet. The problem here is that the District it has is
proxied.
So the fix for that is to change EntityType#getHashCode function like this:
public int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor
factory) {
EntityPersister persister = factory.getEntityPersister(associatedEntityName);
if ( !persister.hasIdentifierPropertyOrEmbeddedCompositeIdentifier() ) {
return super.getHashCode(x, entityMode);
}
Serializable id;
if (x instanceof HibernateProxy) {
id = ( (HibernateProxy) x ).getHibernateLazyInitializer().getIdentifier();
} else {
id = persister.getIdentifier(x, entityMode);
}
return persister.getIdentifierType().getHashCode(id, entityMode, factory);
}
The attached files include:
- a test case to reproduce the problem: run by Maven1 with command maven jar. The error
report gets created under target. The maven assumes that there is j2ee-1.3.1.jar file is
in local Maven repository.
- couple of patches, one for 3.0.5 and another for 3.1
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: