【问题标题】:generate hibernate query from java pojo class从 java pojo 类生成休眠查询
【发布时间】:2019-11-15 22:57:16
【问题描述】:

我想从 pojo 类进行休眠查询,但 pojo 类使用mappedBy。我不知道如何进行正确的查询。

我已经尝试了很多想法,比如ts.clientAccount.clientAccountMapping.id,但它给出了错误。 clientAccountMapping 映射到 clientAccount pojo

头等舱

public class Transaction{
    @ManyToOne
    @JoinColumn
    private ClientAccount clientAccount;    
}

二等

public class ClientAccount{
    @JsonIgnore
    @OneToMany(mappedBy = "clientAccount", cascade = CascadeType.ALL)
    private Set<ClientAccountMapping> clientAccountMapping;
}

三等

public class ClientAccountMapping{
    @Id
    @GeneratedValue(generator="system-uuid")
    @GenericGenerator(name="system-uuid", strategy = "uuid")
    private String id;
}

我的编译器总是给出以下异常:

org.hibernate.QueryException:非法尝试取消引用集合 [transactio0_.idtransactio0_.clientAccount_accountIdclientAccount.clientAccountMapping]

【问题讨论】:

    标签: java hibernate spring-data-jpa hql crud


    【解决方案1】:

    你必须在这里使用加入。喜欢:From ClientAccount c join c.clientAccountMapping

    参考:https://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

    【讨论】:

    • 谢谢,它正在工作。事务 ts JOIN ts.clientAccount.clientAccountMapping 映射 WHERE mapping.id
    • 点个赞!!
    猜你喜欢
    • 2012-05-12
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多