数据库表
一、使用@EmbeddedId
eclipse生成的复合主键类
主键类必需满足下列条件:
(1)必需被序列化
(2)必需有一个公共的无参构造方法
(3)必需实现equals()和hashCode()方法
使用主键类
使用eclipse生成JPA实体的向导界面中,复合主键类的key generator指定为auto,则插件会自动识别数据库表中的复合主键,并生成复合主键类。
这种方法在Entity中获取复合主键中的某列属性如VENDOR_ID时,需要rentCertVendorType.getRentCertVendorTypePK().getVendorId(),其中rentCertVendorType为RentCertVendorType类对象。
二、使用@IdClass
主键类
Entity
这种方法在Entity中获取复合主键中的某列属性如VENDOR_ID时,只需要rentCertVendorType.getVendorId(),其中rentCertVendorType为RentCertVendorType类对象。