无法解析实体的属性

时间:2018-08-05 16:20:03

标签: java hibernate spring-data-jpa single-page-application

我具有以下实体配置:

主表:

@Entity
@Table
public class Merchants {

    @Id
    private int id;

    @OneToMany(mappedBy = "merchants")
    private List<Contracts> contracts;
}

@Entity
@Table
public class Contracts {

    @Id
    private int id;

    @Column(length = 255)
    private String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "merchant_id")
    private Merchants merchants;
}

我使用此JPA查询:

String hql = "select e from " + Contracts.class.getName() + " e where e.merchant_id = ?";

        Query query = entityManager.createQuery(hql).setParameter(0, merchantId);

当我部署程序包时,存在表列商人ID。 但是我在SQL查询期间遇到异常:

Caused by: org.hibernate.QueryException: could not resolve property: merchant_id of: org.rest.api.entity.Contracts [select e from org.rest.api.entity.Contracts e where e.merchant_id = ?]

您知道为什么没有映射mercer_id吗?

1 个答案:

答案 0 :(得分:1)

需要使用商家ID。

尝试一下:

String hql = "select e from " + Contracts.class.getName() + " e where e.merchants.id = ?";