开发者

org.hibernate.QueryException: illegal attempt to dereference collection - SubQuery error

开发者 https://www.devze.com 2023-03-21 16:54 出处:网络
I try similar questions but without success. Please, Can someone help me on the question. I have the following POJOs:

I try similar questions but without success. Please, Can someone help me on the question. I have the following POJOs:

@Entity
public class EntityA implements Serializable  {

private static final long serialVersionUID = 1L;


@Id
@GeneratedValue(strategy = GenerationType.AUTO) 
private int id;

@Column(length=9)
private String someField;

@Column(length=50)
private String anotherField;

Getters and Setters ......




    @Entity
    public class EntityB {


private static final long serialVersionUID = 1L;


@Id
@GeneratedValue(strategy = GenerationType.AUTO) 
private int id;


@OneToMany(cascade={CascadeType.ALL} )
private List<EntityA> listOfEntityA;


Getters and Setters ......

And I try to retrieve a list of objects of EntityA that are not present in the field list contained in EntityB

return (List<EntityA>) genericDAO.retrieveList("from EntityA e1 where e1.id not in ( select e2.listOfEntityA.id from EntityB e2 where e2.id =?1)" , myParamId );
开发者_开发知识库

and caught the exception

org.hibernate.QueryException: illegal attempt to dereference collection

Already tried also without subquery, passing as parameter the list of objects EntityA contained in the field of entityB, but again without success.

Can anyone tell me where I am wrong

Thanks in advance


Try this query:

String query =
    "SELECT entityA " +
    "FROM EntityA entityA " +
    "WHERE entityA.id NOT IN (" +
    "   SELECT entityAOfB.id " +
    "   FROM EntityB entityB " +
    "   JOIN entityB.listOfEntityA entityAOfB " +
    "   WHERE entityB.id = ?1";
    ")";
0

精彩评论

暂无评论...
验证码 换一张
取 消