@Formula的替代方案?

时间:2017-10-12 09:00:57

标签: mysql hibernate jpa spring-data

我有两个对象:

@Table(name = "user")
User
@Id
Integer id
Integer uuid;

和预订:

@Table(name = "reservation")
Reservation
@Id
Integer id;
Integer uuid;

我的目标是:

@Table(name = "reservation")
Reservation
@Id
Integer id;
Integer uuid;

@Formula("(SELECT * FROM user b  WHERE b.uuid = uuid )")
List<User> users;

问题是@Formula无法与对象一起使用。

如何使用相同的uuid包含预订中所有用户的列表?

我发现了这个,但也许有更好的选择 https://stackoverflow.com/a/37502703/3871754

1 个答案:

答案 0 :(得分:0)

Support of relationships that references non-PK columns is an optional feature. In simple cases it's supported by Hibernate

@NotAudited
@OneToMany
@JoinColumn(name = "uuid", referencedColumnName = "uuid")
private List<Barrier> barriers = new ArrayList<>();

and implemented Serializable for Reservation