Entity collections are not loaded when database uses fixed-width columns for primary/foreign keys

Description

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.

Environment

None

Activity

Show:
Nathan Xu
September 21, 2020, 1:42 PM

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.

Assignee

Nathan Xu

Reporter

Mariano Eloy Fernández Osca

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure