【发布时间】:2021-11-01 15:42:18
【问题描述】:
我在数据库中自动生成实体,使用效果很好:
spring.jpa.hibernate.ddl-auto=update
现在我需要关联表中的一个附加属性,如果不手动创建关联实体,我无法弄清楚。下面列出的当前类生成一个没有附加属性的关联表。
我需要的桌子:
persons:
id
search_requests:
id
search_requests_persons:
person_id
search_request_id
study_id
我目前拥有的课程(简化):
@NoArgsConstructor
@RequiredArgsConstructor(staticName = "of")
@Getter
@Setter
@Entity
@EqualsAndHashCode
@Table(name = "persons")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long id;
// The following line is what I would need
// private List<Integer> studyIds;
}
@NoArgsConstructor
@RequiredArgsConstructor(staticName = "of")
@Getter
@Setter
@Entity
@EqualsAndHashCode
@Table(name = "search_requests")
public class SearchRequest {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long id;
@NonNull
@ManyToMany
private List<Person> persons;
}
我将 Lombok 和 Javax Persistence 用于注释。
【问题讨论】:
标签: java spring spring-boot jpa