stdh (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63739fa...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDcxMDZjYTc1...
) / Improvement (
https://hibernate.atlassian.net/browse/HHH-15722?atlOrigin=eyJpIjoiNDcxMD...
) HHH-15722 (
https://hibernate.atlassian.net/browse/HHH-15722?atlOrigin=eyJpIjoiNDcxMD...
) Feature request: bidirectional @Any mapping (
https://hibernate.atlassian.net/browse/HHH-15722?atlOrigin=eyJpIjoiNDcxMD...
)
Issue Type: Improvement Assignee: Unassigned Created: 15/Nov/2022 07:24 AM Priority: Minor
Reporter: stdh (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63739fa...
)
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 (
https://discourse.hibernate.org/t/bidirectional-any-mapping/6893
) ). 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?
(
https://hibernate.atlassian.net/browse/HHH-15722#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15722#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100210- sha1:28a3636 )