Skip to content
Advertisement

Error accessing field by reflection for persistent property [model.Credentials#email] on @EmbeddedID

I’ve been experiencing problems implementing the Authorities on my spring boot application, and after digging a little I realised that maybe the association between my Credentials and Authorities tables, was wrong.

In fact it come to my attention that Spring allowed every type of user, (regardless their authority) to access ever method, even the ones I though have been secured. At that point, I implemented a .findAll() method to actually see if there was some kind of problem on the association, and indeed there was.

Let me show first the MySQL tables:

JavaScript

Before jumping onto the associations in the entities, it’s worth noting that the authorities entity has and embedded key reflecting the design of the table. So the email column its a foreign key and a primary at the same time:

JavaScript

Credentials class:

JavaScript

Removing the bilateral association (thus leaving it just on the AuthoritiesKey class), hibernate successfully returns all the credentials (without their authorities of course), and all the authorities (this time preceded by the credentials).

I cannot wrap my head around it.

The complete meaningful stack trace i get when I leave the bilateral association is the following:

JavaScript

Where 64 is the id of the (last, but get called first) row in the Credential table.

=== UPDATE ===

JavaScript

Advertisement

Answer

It looks like you can not use @OneToOne here due to the hibernate bug. (See HHH-3824) It’s reproduced even with Hibernate 5.4.28.Final

As workaround, I would suggest you to correct your mapping in this way:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement