If I have the following entities:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name = "type",
discriminatorType = DiscriminatorType.STRING
)
public abstract class TimeCode {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@NaturalId
@Column(name = "code", unique = true, nullable = false)
private String code;
}
@Entity
@DiscriminatorValue("task")
public class TaskCode extends TimeCode { }
@Entity
public static class Post {
@Id
@GeneratedValue
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "task", referencedColumnName = "code")
public TaskCode task;
}
I get the following error:
referencedColumnNames(code) of Post.task referencing TaskCode not mapped to a single property
Why? Is this a Hibernate bug? How can I correctly create a join using the code
natural id of TimeCode
?
You can see the full test case here: https://github.com/jonrimmer/hibernate-orm/commit/53121132cb3db6b508cbf6ab46b5331c6b640d3f