我的问题与hibernate中的this完全相同,但减去了排序。
我有两个表,Person
和Fruit
@Entity
@Table(name = "person")
public class Person {
@Id
@Setter
@Getter
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;
@Getter
@Setter
private String name;
@Getter
@Setter
@Column(name = "fruit_ids")
private Integer[] fruitIds;
}
Table "public.person”
Column | Type | Modifiers | Storage | Stats target | Description
---------------------+--------------------------------+---------------------------------------------------+----------+--------------+------------------------------------------
id | integer | not null default nextval(‘person_seq'::regclass) | plain | |
name | character varying(255) | | extended | |
fruit_ids | integer[] | | extended | |
和水果
@Entity
@Table(name = “fruit”)
public class Fruit {
@Id
@Setter
@Getter
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;
@Getter
@Setter
private String name;
}
Table "public.fruit”
Column | Type | Modifiers | Storage | Stats target | Description
---------------------+--------------------------------+---------------------------------------------------+----------+--------------+------------------------------------------
id | integer | not null default nextval(‘fruit_seq'::regclass) | plain | |
name | character varying(255) | | extended | |
我想要接近的是select p from person p join fruit f on f.id = any(p.fruit_ids) where p.id = 5;
如何在Hibernate中执行此操作?我目前有
@Getter
@Setter
@OneToMany
@JoinColumn(name = "fruit_ids", referencedColumnName = "id")
private List<Fruit> Fruits= new ArrayList<>();
但它给了我错误。请注意,fruit_ids
表格中的person
是{strong>数组integer
。这不是老派在mysql中的一对多关系。