Feature request: bidirectional @Any mapping

Description

I’d like to request support for the inverse side of an @Any mapping. For example a Task containing SubTasks, both of which could exhibit TaskExceptions (I described this example in this Discourse topic). Code would be something like this:

public interface Excepted { ... } @Entity public class TaskException { @Any @AnyDiscriminator(DiscriminatorType.STRING) @AnyDiscriminatorValues({ @AnyDiscriminatorValue(discriminator = "Task", entity = Task.class), @AnyDiscriminatorValue(discriminator = "SubTask", entity = SubTask.class)}) @AnyKeyJavaClass(String.class) @Column(name = "excepted_type") @JoinColumn(name = "excepted_id") private Excepted excepted; ... } @Entity public class Task implements Excepted { @OneToMany(mappedBy = "excepted") private List<TaskException> exceptions = new ArrayList<TaskException>(); ... } @Entity public class SubTask implements Excepted { @OneToMany(mappedBy = "excepted") private List<TaskException> exceptions = new ArrayList<TaskException>(); ... }

Maybe inverse of an @Any would not be a ‘clean’ @OneToMany, perhaps it should be named @AnyToMany or something? Anyway, at the moment the code above doesn’t work, but something like this is will:

@OneToMany @JoinColumn(name = "excepted_id") @Where(clause = "excepted_type = 'Task'") private List<TaskException> exceptions = new ArrayList<TaskException>();

If implementation of a new or expanded annotation is infeasible or undesirable, maybe the use of the @JoinColumn and @Where annotations could be documented?

Attachments

1
  • 09 Jan 2023, 02:33 PM

Activity

Show:

Vincent Bouthinon April 4, 2024 at 1:18 PM
Edited

Vincent Bouthinon January 9, 2023 at 2:34 PM

I took the liberty of adding a test that reproduces (JPAUnitTestCase)

Vincent Bouthinon January 9, 2023 at 1:54 PM

Hello,
I exposed the same problem here: @OneToMany with interface type return variable (role column) @Any - Hibernate ORM - Hibernate
I think there is no need to recreate

Fixed

Assignee

Reporter

Fix versions

Priority

Created November 15, 2022 at 3:24 PM
Updated October 15, 2024 at 1:48 PM
Resolved June 5, 2024 at 6:33 AM