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;

本文详细介绍了在SpringMVC中如何配置实体类的父子关系,包括使用@Entity注解定义实体类,@Table注解指定表名,@Inheritance注解设置继承策略,以及如何在子类中实现特定属性和关系。通过示例代码,深入理解SpringMVC中实体类的继承和关联关系的配置。

1419

被折叠的 条评论
为什么被折叠?



