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? |