Wrong binding of @ManyToOne for non-PK associations
Activity
![](https://secure.gravatar.com/avatar/0a81b8b5d21688d12a820dd0516853fd?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FCB-4.png)
Christian Beikov December 13, 2024 at 2:00 PM
Hibernate ORM 6 has completely different code paths for this use case and is not affected by this anymore.
![](https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/VN-3.png)
Victor Noël June 21, 2021 at 7:48 AM
I’m facing the same problem with version 5.4.32.Final
: I have a class annotated with @Table(name = "A", uniqueConstraints = {@UniqueConstraint(columnNames = {"c1", "c2"})})
And in another class I refer to it using @JoinColumns
:
So I would expect that because of the unique constraint declared, there is no need for class A
to be marked as Serializable
.
Am I mistaken?
Brian Bober March 18, 2021 at 3:10 AMEdited
It doesn’t have to be labeled a unique association. It’s more general than that, in code at least (though in db, the column in foo_bar_baz below is unique, effectively, but not labelled unique in the db or code). Yes, I know that’s bad form but this is just sync data fed by Kafka. I thought the demonstration of a slightly different variant would be useful. Example, see foo below. Adding implements Serializable
solved it even though it’s not unique. Names have been changed to generalize (ever popular foo, bar, baz)
and its binding for a join
![](https://secure.gravatar.com/avatar/0789e5930cac19b72563bb08f118f860?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FMB-6.png)
Marco Bettiol April 23, 2020 at 9:19 AM
Hi, any update?
![](https://secure.gravatar.com/avatar/c12580c625d3f9e48edefc018848895f?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FCB-2.png)
Chandrashekhar B December 17, 2019 at 7:49 AM
you have to serialize Other class and Example class
This one is quite obscure, the problem is most likely in BinderHelper#createSyntheticPropertyReference().
A many-to-one foreign key association that doesn't reference a primary key, but a unique key:
Throws an exception when you query Items:
Note that this is one of those rare use cases for "property-ref" in XML binding.