I have a column that contains a string, representing the name (and thereby primary key) of another entity, to which I am attempting to join the columns to store the entity in the parent. The entities look like so:
@Entity
public class Thing {
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Id
@Column(name = "thingname")
private String name;
}
@Entity
public class Consumer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "sourcething")
private String source;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "sourcething", referencedColumnName = "thingname")
private Thing thing;
}
This will throw a mapping error, denoting duplicate column mappings, so from this question I added the additional arguments:
@JoinColumn(name = "sourcething", referencedColumnName = "thingname", insertable = false, updatable = false)
However, this beings to fail with ConstraintViolationExceptions
during unit testing.
Is there something I am missing for completing this mapping/column join?