Note that there are some explanatory texts on larger screens.

plurals
  1. POjpql object IN list without CriteriaBuilder
    primarykey
    data
    text
    <p>i have to get all <code>Invoice</code> where <code>Invoice.responsible</code> IN a list of <code>Usergroup</code>?</p> <p>I tried following:</p> <pre><code>public List&lt;Invoice&gt; getOldestInvoiceWithOpenBenefits(List&lt;Usergroup&gt; usergroups) { TypedQuery&lt;Invoice&gt; q = em.createQuery("SELECT i FROM Invoice i WHERE (i.responsible IN (:usergroups)) AND " + " i.entered = false AND i.totalcosts &gt; (SELECT SUM(b.costs) FROM Benefit b WHERE b.invoice = i) ORDER BY i.creationdate ASC", Invoice.class); q.setParameter("usergroups", usergroups); q.setMaxResults(10); return q.getResultList(); } </code></pre> <p>but i alwasy get this error:</p> <pre><code>Information: /pages/index.xhtml Warnung: EJB5184:A system exception occurred during an invocation on EJB InvoicEJB, method: public java.util.List de.ltg.sachzuwendungen.ejb.InvoicEJB.getOldestInvoiceWithOpenBenefits(java.util.List) Warnung: javax.ejb.EJBException [...Stacktrace] Caused by: Exception [EclipseLink-6075] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryException Exception Description: Object comparisons can only use the equal() or notEqual() operators. Other comparisons must be done through query keys or direct attribute level comparisons. Expression: [ Relation operator [ IN ] Query Key responsible Base de.ltg.sachzuwendungen.db.entity.Invoice Constant [ Parameter usergroups]] at org.eclipse.persistence.exceptions.QueryException.invalidOperatorForObjectComparison(QueryException.java:646) [...Stacktrace] </code></pre> <p>Can someone help me to get this work without using the CriteriaBuilder? If you need the database entities just ask.</p> <p>Thank you in advance.</p> <p><strong>EDIT:</strong></p> <p>Invoice Entity:</p> <pre><code>@Entity @Table(name = "t_invoice") public class Invoice implements Serializable { private static final long serialVersionUID = 1L; @Version @Column(name = "version") /** * Optimistic Locking */ private int version; @Id @Column(name = "id") private int id; @Column(name = "number") private String number; @Column(name = "name") private String name; @Column(name = "description") private String description; @Column(name = "totalcosts") private double totalcosts; @Temporal(TemporalType.DATE) @Column(name = "issuedate") private Date issuedate; @Temporal(TemporalType.DATE) @Column(name = "creationdate") private Date creationdate; @Column(name = "entered") private boolean entered; @JoinColumn(name = "idUser_creator", referencedColumnName = "id") private User creator; @JoinColumn(name = "idUsergroup_responsible", referencedColumnName = "id") private Usergroup responsible; @OneToMany(mappedBy = "invoice") private List&lt;Benefit&gt; benefits; public Invoice() { // TODO Auto-generated constructor stub } /*Getter &amp; Setter*/ .. /*Override toString()*/ .. } </code></pre> <p>Usergroup Entity:</p> <blockquote class="spoiler"> <p></p> </blockquote> <pre><code>@Entity @Table(name = "t_usergroup") public class Usergroup implements Serializable { private static final long serialVersionUID = 1L; @Version @Column(name = "version") /** * Optimistic Locking */ private int version; @Id @Column(name = "id") private Integer id; @Column(name = "name") private String name; @ManyToMany(targetEntity = Right.class, fetch = FetchType.LAZY) @JoinTable(name = "t_mapUsergroupToRight", joinColumns = { @JoinColumn(name = "idUsergroup") }, inverseJoinColumns = { @JoinColumn(name = "idRight") }) private List&lt;Right&gt; rights; @ManyToMany(targetEntity = User.class, fetch = FetchType.LAZY) @JoinTable(name = "t_mapUserToUsergroup", joinColumns = { @JoinColumn(name = "idUsergroup") }, inverseJoinColumns = { @JoinColumn(name = "idUser") }) private List&lt;User&gt; users; /*Getter &amp; Setter*/ .. /*Override toString() &amp; equals() &amp; hashCode()*/ .. } </code></pre> <blockquote class="spoiler"> <p></p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload