JPA,OneToMany和ManyToOne

时间:2016-07-12 09:41:36

标签: java sql jpa orm

我正在使用JPA从DB查询数据。我得到了:

@Entity
@Table(name = "supporter_1")
public class Supporter{

    @Id
    ...
    @OneToMany(mappedBy = "supporter")
    List<SubSupporter> subSuporter= new ArrayList<SuBSupporter>();

第二节课:

@Entity
@Table(name = "supporter_2")
public class SubSupporter{

    @Id
    private Long id;
    ...
    @ManyToOne
    @JoinColumn(name = "supporter_1.id", nullable=false)
    Supporter supporter;

当我试图获取所有支持者并在循环中访问它们时它没问题,但在尝试访问subSupporter列表后我收到错误:

[EL Warning]: 2016-07-12 11:29:45.282--ServerSession(180353207)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The multi-part identifier "supporter_1.id" could not be bound.
Error Code: 4104
Call: SELECT ID, coulmn_name, supporter_1.id FROM supporter_2 WHERE (supporter_1.id = ?)
    bind => [1 parameter bound]
Query: ReadAllQuery(name="subSupporter" referenceClass=SubSupporter sql="SELECT ID, coulmn_name, supporter_1.id FROM supporter_2 WHERE (supporter_1.id = ?)")

我看到选择陈述是错误的,我不知道为什么。

PS我正在使用eclipse链接

1 个答案:

答案 0 :(得分:0)

您不能在名称supporter_1.id列中添加一个点。将其更改为supporter_1_id