我已经连续几个晚上在做这件事情。我想将用户中的号码(一位用户对应多个号码)与号码中的用户(多个号码对应一位用户)进行链接。但不幸的是,我一直无法成功,需要您的帮助和知识。无论我做什么,都会出现错误。请给予一个明确的解决方案。
application.properties:
spring.jpa.hibernate.ddl-auto=validate
用户实体:
@Entity
@Table(name = "user")
public class Users implements Serializable {
private static final long serialVersionUID = 2323232323L;
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<Number> number;
数字实体:
@Entity
@Table(name = "number")
public class Number implements Serializable {
private static final long serialVersionUID = 1212121212L;
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
private Users user;
Liquibase:
<createTable tableName="user">
<column name="id" type="BIGINT(8)" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="fk_number" type="BIGINT"/>
</createTable>
<createTable tableName="number">
<column name="id" type="BIGINT(8)" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="user" type="BIGINT"/>
</createTable>