Wrong binding of @ManyToOne for non-PK associations

Description

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.

Activity

Show:

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.

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 AM
Edited

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

 

Marco Bettiol April 23, 2020 at 9:19 AM

Hi, any update?

Chandrashekhar B December 17, 2019 at 7:49 AM

you have to serialize Other class and Example class

Out of Date

Assignee

Reporter

Affects versions

Priority

Created October 4, 2012 at 10:26 AM
Updated December 13, 2024 at 2:00 PM
Resolved December 13, 2024 at 2:00 PM
Loading...