hibernate使用

1、eneity定义时,需要配置多对一关系,使用如下配置:

@Fetch(FetchMode.SELECT)
    @ManyToMany(targetEntity =CompanyAccountingData.class, fetch = FetchType.EAGER)
    @JoinTable(name = "t_company_accounting",joinColumns = @JoinColumn(name = "id"))
    @Column(name="companyaccounting")
//    List<Lawyer> responsibleLawyers
    List<CompanyAccountingData> accountingDataList= new ArrayList<CompanyAccountingData>();;

2、需要多个字段作为主键时,使用如下配置:

 @GeneratedValue(strategy= GenerationType.AUTO)
    @EmbeddedId
    MailTaskPK id;
@Embeddable
public class MailTaskPK  implements java.io.Serializable{
    private static final long serialVersionUID = 1L;
    @Column(name="mailID")
    Integer mailID;
    @Column(name="comEmail")
    //公司的邮箱地址,发送者根据
    String comEmail;
	}
}

3、一对一关系,使用如下配置:

 @OneToOne(mappedBy = "id",cascade = CascadeType.ALL)
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页