Getting @Id of lazy-loaded @ManyToOne entity allways returns null

Description

For attached classes calling aidConfiguration.getChipApplication().getId() allways returns null. Other properties, eg. aidConfiguration.getChipApplication().getVersion() returns correctly the value from DB. If chipApplication is not lazy loaded (see the comment in the code), then aidConfiguration.getChipApplication().getId() returns correct non-null value.

Question on Stackoverflow: http://stackoverflow.com/questions/28213990/getting-id-of-lazy-loaded-manytoone-entity-allways-returns-null/28214074

Environment

Linux bono 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt2-1 (2014-12-08) x86_64 GNU/Linux
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-2)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
mysql Ver 14.14 Distrib 5.5.40, for debian-linux-gnu (x86_64) using readline 6.3

Activity

Show:
Gail Badner
December 6, 2016, 12:11 AM

, is a final getter method supported for bytecode-enhanced entities when using field access?

Luis Barreiro
December 7, 2016, 3:42 PM

yes. Even if a method is final, it's bytecode gets modified to call the right places.

Steve Ebersole
December 7, 2016, 4:22 PM

To clarify... that is only ever a problem with proxing since the proxy is a subclass and would not be able to override the final super method. Bytecode enhancement does not generate a subclass, it literally rewrites that class's bytecode.

Steve Ebersole
December 7, 2016, 4:23 PM

And in regards to proxying, both JPA and Hibernate (docs) clearly state that that is not a valid qualifier for a persistent attribute. You'd have to use field-access there.

cnsgithub
March 13, 2019, 3:28 PM

Encountered the same issue with Hibernate 5.4.1.Final when using @ManyToOne(fetch = FetchType.LAZY) and final @Id accessors.

Dropping the final keyword is working just fine.

Assignee

Unassigned

Reporter

Martin Ždila

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure