0
我有ManyToMany
關係的2個模型。試了這個,它的工作原理:ManyToMany bean模型沒有Id值
@Entity
public class EmployeeProfile extends Model {
@Id
public Long id;
@ManyToMany
public List<Expertise> expertises;
}
@Entity
public class Expertise extends Model {
@Id
public Long id;
@Constraints.Required
public String name;
}
是的。在這個模型中,我沒有List<EmployeeProfile>
Expertise
方面,但它的工作原理。
這不起作用,即使expertises
是空的:
@Entity
public class EmployeeProfile extends Model {
@Id
public Long id;
@ManyToMany
public List<Expertise> expertises;
}
@Entity
public class Expertise extends Model {
@Id
public UUID id;
@Constraints.Required
public String name;
}
它顯示ManyToMany bean [email protected] does not have an Id value.
這隻有expertises
爲空:
@Entity
public class EmployeeProfile extends Model {
@Id
public Long id;
@ManyToMany(cascade = CascadeType.PERSIST)
public List<Expertise> expertises;
}
@Entity
public class Expertise extends Model {
@Id
public UUID id;
@Constraints.Required
public String name;
}
在第三個例子,當expertises
不爲空時,它顯示重複錯誤。顯然,當我試圖保存一個EmployeeProfile
對象並且該對象具有expertises
中的對象時,它將嘗試保存Expertise
對象,即使我只想保存EmployeeProfile_Expertise
關係,而不是Expertise
本身。
任何想法,使其工作?