我有两个表,我想建立一个关系,但是从文本文件加载数据的方式,如果我不能引用 Artist
班级 Artwork
类,但使用包含艺术家姓名的字符串作为外键。但我不明白的是,如何陈述从艺术品到艺术家之间的多对一关系,而不是:
@ManyToOne
@JoinColumn(name = "name")
private Artist artist;
而是使用下面的及其类型来建立这种关系 String artist
在artwork类中使用 name
在艺术课上。
艺术家:
@Entity
@Table(name = "artist", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Artist implements Manageable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "name")
private String name;
@Column(name = "sex")
private String sex;
@Column(name = "country")
private String country;
@Column(name = "dob")
private int dob;
艺术品:
@Entity
@Table(name = "artwork", uniqueConstraints = @UniqueConstraint(columnNames = "title"))
public class Artwork implements Manageable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "title")
private String title;
@Column(name = "country")
private String country;
@Column(name = "year")
private int year;
@Column(name = "artist")
private String artist;
有没有办法做到这一点,或者我需要重新考虑我的方法?
暂无答案!
目前还没有任何答案,快来回答吧!