I have a class and I need just a single column from another mapped entity. I would prefer to void having a full reference. Is there a way to do this? I've exhaustively googled but I must not have the terminology right.
Explained:
@Entity
@Table(name = "foo")
@Data
public class Foo {
@Id
@Column(name = "itemid")
private long id;
@Column(name = "name")
private String name;
}
This works:
@Entity
@Table(name = "bar")
@Data
public class Bar{
@Id
@Column(name = "itemid")
private long id;
@Column(name = "other_name")
private String otherName;
@OneToOne
@PrimaryKeyJoinColumn
private Foo foo;
}
But I want:
@Entity
@Table(name = "bar")
@Data
public class Bar{
@Id
@Column(name = "itemid")
private long id;
@Column(name = "other_name")
private String otherName;
@OneToOne
@JoinColumn(name = "itemid")
@Formula("SELECT name FROM FOO v where v.id = id")
// Something here...not sure what. Where name is the name from Foo
private String name;
}