0

I want to make hibernate query from pojo class, but pojo class uses mappedBy. I don't know how can I make proper query.

Already I have tried many ideas, like ts.clientAccount.clientAccountMapping.id but it gives error. clientAccountMapping is mapped in clientAccount pojo

first class

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

second class

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

third class

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

Always my compiler gives the following exception:

org.hibernate.QueryException: illegal attempt to dereference collection [transactio0_.idtransactio0_.clientAccount_accountIdclientAccount.clientAccountMapping]

1 Answer 1

1

you have to use join here. like : From ClientAccount c join c.clientAccountMapping

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

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, it is working. Transaction ts JOIN ts.clientAccount.clientAccountMapping mapping WHERE mapping.id
give a thumbs up!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.