无法从实体解析属性

我有这些实体配置:


主表:


@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);

部署包时存在表列merchant_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 = ?]

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


慕仙森
浏览 151回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java