we are experiencing some weird bug with a more than 2years old hibernate installation.
We're using Hibernate3.1.2.
Our database is SQLServer2000, using a
case-insensitive collation
Some entities are unable to load their child entities:
for instance:
Code:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.xx.common.model.of.OrganismeFormation#c300]
This happens when an entities having a reference to this "c300" object tries to load it. In the table, the reference to the PK is "c300" and not "C300".
The object PK is 'C300', uppercase, but SQL requests are case-insensitive.
When trying to execute the Hibernate generated query manually against the db, it similarly works.
The error seems to come from the AbstractType class method:
Code:
public boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory) {
return isEqual(x, y, entityMode);
}
When the exception occurs, the method is trying to compare "c300" against "C300", and fails since the isEqual is case-sensitive.
The weird thing is that Hibernate is
case-insentitive when loading an instance:
in this precise case:
Code:
load(OrganismeFormation, "c300")
works, as well as
Code:
load(OrganismeFormation, "C300")
.
I'm having a hard time to understand how Hibernate works in this case. But it seems to me that it's not an expected behavior.
Why would Hibernate accept to load "c300" when the PK in the DB is "C300" and fire an exception when trying to load it as a child reference?
That's not a consistent behavior.
I'm trying to setup a complete exemple to demonstrate the error, but I'd be glad to know first if the Hibernate team is aware of this and if this problem has already happend to anyone.
Admittedly our database shouldn't have foreign key reference in lower case when our PK policy is all upper case.
We are trying to fix this, but it's a wide spread error, since from the start Hibernate never complained about it, we took it for granted that it would
continue to behave as such.
I originally believed that Hibernate would store the real PK (as written in the DB) for any FK when creating an entity with child references. And not the String used to load it.
Hibernate version:3.1.2
Db:SQLServer2000SP4
cheers,