0

我正在尝试返回一组不属于这样的集合的对象:

    TypedQuery<Extra> q = em
            .createQuery(
                    "SELECT e FROM Extra e, Arrangement a WHERE "
                        + "a.id = :arrid AND e NOT MEMBER OF a.extras",
                    Extra.class);
    q.setParameter("arrid", a.getId());
    return q.getResultList();

但我从中得到了一个糟糕的 SQL:

Caused by: org.h2.jdbc.JdbcSQLException: Subquery is not a single column query; SQL statement:
select extra0_.code as code427_, extra0_.edition_number as edition5_427_,
extra0_.totalCost as totalCost427_, extra0_.unitCost as unitCost427_,
extra0_.units as units427_ from extra_arrangements extra0_
cross join arrangements arrangemen1_
where arrangemen1_.id=? and
((extra0_.code, extra0_.edition_number) not in
  (select extra3_.code, extra3_.edition_number
   from arrangements_extra_arrangements extras2_, extra_arrangements extra3_
   where arrangemen1_.id=extras2_.arrangements_id and
   extras2_.extras_code=extra3_.code and
   extras2_.extras_edition_number=extra3_.edition_number)) [90052-161]

问题是这个其他查询按预期工作:

    TypedQuery<Exhibitor> q = em.createQuery(
        "SELECT e FROM Exhibitor e, Edition ed WHERE ed.number = :ednum AND "
        + "e NOT MEMBER OF ed.exhibitors",
        Exhibitor.class);
    q.setParameter("ednum", e.getNumber());
    return q.getResultList();

唯一的区别是 Exhibitor 有一个列 id,而 Extra 有一个复合键:

@Entity
@Table(name = "exhibitors")
public class Exhibitor implements Serializable, Comparable<Exhibitor> {

    @Id
    private int id;
    @Column(length = 100)
    private String code;
    @ManyToMany
    private List<Edition> edition;
    ...
}

额外的:

@Entity
@Table(name="extra_arrangements")

public class Extra implements Serializable {

    @EmbeddedId
    private ExtraCode id;
    private double unitCost;
    private double units;
    ...
}


@Embeddable
public class ExtraCode implements Serializable {

    private String code;
    @ManyToOne
    private Edition edition;

    //Getters and setters omitted
}

知道我可能做错了什么以及如何解决吗?

4

1 回答 1

0

我认为这与此问题相同。
H2 does not currently support that style of IN query.

sql-query 中有问题的地方:

  和 (
    (
      extra0_.code,
      extra0_.edition_number
    ) 不在
    (选择 ...)
  )
于 2012-04-17T18:37:45.460 回答