SpringMVC 中实体类父子类关系设置 博客分类: SpringMVC 中实体类父子类关系设置J2EEJ2SE SpringMVC 中实体类父子类关系设置springmvcinheritancetypeinheritanceentity
程序员文章站
2024-03-16 19:24:34
...
SpringMVC 中实体类父子类关系设置
父类:
@Entity
@Table(name="tbl_AlbumSuper")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class AlbumSuperClass {
@Id
@Column(length = 32)
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(strategy = "uuid", name = "system-uuid")
private String strID;
@Column
private String strName;
}
子类:
@Entity
public class VideoAlbum extends AlbumSuperClass{
//写一些子类特有的属性,如:
@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="FK_album_ID")
private Set<Video> videoSet;
}
Video实体中专辑对象为父类对象
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "FK_album_ID")
private AlbumSuperClass beanSuperAlbum;
父类:
@Entity
@Table(name="tbl_AlbumSuper")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class AlbumSuperClass {
@Id
@Column(length = 32)
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(strategy = "uuid", name = "system-uuid")
private String strID;
@Column
private String strName;
}
子类:
@Entity
public class VideoAlbum extends AlbumSuperClass{
//写一些子类特有的属性,如:
@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="FK_album_ID")
private Set<Video> videoSet;
}
Video实体中专辑对象为父类对象
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "FK_album_ID")
private AlbumSuperClass beanSuperAlbum;