I'm using Hibernate to access a legacy Sybase database.
The database is using char(10) columns for primary and foreign keys.
The JTDS driver returns values padded with spaces up to column length.
Take two entities, A and B, where A holds a @OneToMany List of B.
Also, database holds a row for A with id "a" and a related row for B with id "b".
When loading an entity A by id "a", it always returns an empty List of B.
This happens because StatefulPersistenceContext caches entitiesByKey
with id "a", but Hibernate loads "b" with foreign key "a ".
When method getCollectionOwner(Serializable, CollectionPersister)
tries getEntity(EntityKey key), it does not find it.
Here's a Eclipse project including a JPAUnitTestCase with a failing and a passing test.
H2 has been configured with "MODE=PostgreSQL" to emulate padded values for fixed-length columns.
Thanks for the bug reporting. I created a (DRAFT) PR here: . Currently it only includes the testing case by you. Will work on it later.