开发者社区> 问答> 正文

带有@EmbeddedId的Spring-Data @oneToMany无法映射到单个属性

我正在尝试在Rent表和RentAgreement表之间建立oneToMany关系,rent表具有复合键rentKey

@Setter
@Getter
@Entity
@Table(name = "Rent")
public class Rent {

    @EmbeddedId
    @Column(name = "rentKey")
    private RentKey rentKey;

    @OneToMany(mappedBy="rent", cascade = {CascadeType.REFRESH, CascadeType.REMOVE})
    @JsonIgnoreProperties(value = "rent", allowSetters=true)
    private Set<RentalAgreement> rentalAgreements;
...

RentKey是

@Data
@Setter
@Getter
@Embeddable
public class RentKey implements Serializable{
    private String rentStartDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "agent_id", referencedColumnName = "id")
    @JsonIgnoreProperties(value = "rents", allowSetters=true)
    private Agent agent;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "client_id", referencedColumnName = "id")
    @JsonIgnoreProperties(value = "rents", allowSetters=true)
    private Client client;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "propertyRent_id", referencedColumnName = "id")
    @JsonIgnoreProperties(value = "rents", allowSetters=true)
    private PropertyRent propertyRent;
    ...

而RentAgreement是

@Data
@Entity
@Table(name = "RentalAgreement")
public class RentalAgreement {
    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
            @JoinColumn(name="agent_id", referencedColumnName="agent_id"),
            @JoinColumn(name="client_id", referencedColumnName="client_id"),
            @JoinColumn(name="propertyRent_id", referencedColumnName="propertyRent_id")
    })
    @JsonIgnoreProperties(value = "rentalAgreements", allowSetters=true)
    private Rent rent;
    ...

当我运行代码时,我得到

org.hibernate.AnnotationException:引用com.mikason.PropView.dataaccess.commercialEntity.Rent的com.mikason.PropView.dataaccess.documentEntity.RentalAgreement.rent的referencedColumnNames(agent_id,client_id,propertyRent_id)未映射到单个属性

谁能告诉我我做错了什么?谢谢

展开
收起
垚tutu 2019-12-04 16:38:00 850 0
0 条回答
写回答
取消 提交回答
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多