Hibernate Annotation多表继承映射存储与查询

一.存储Annotation

@Entity
@Table(name="t_goods")
@Inheritance(strategy=InheritanceType.JOINED)
public class Goods
{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    @Column(name="gname")
    private String name;
    private float price;
    private String introduce;
    private int smallType;
    private String pic;
    ...
}
@Entity
@Table(name = "t_goods_book")
@PrimaryKeyJoinColumn(name = "id")
public class Goods_Book extends Goods
{
    private String writer;
    private String publisher;
    private String publish_time;
    ...
}

二.查询

    查询后向下转型即可

你可能感兴趣的:(Hibernate,annotation,查询,存储,多表继承映射)