Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] questiona about JPQL and Collections

Hi Daniel,

Because BasicCollection is not a part of the JPA specification yet, JPQL cannot currently query across BasicCollections. (That behavior is expected in the upcoming JPA 2.0 specification)

To access a BasicCollection in a query, you will have to use EclipseLink's criteria API instead.

  Your code will look something like this:

ReadAllQuery query = new ReadAllQuery(RecordDAO.class);
ExpressionBuilder record = new ExpressionBuilder();
Expression attributes = record.anyOfAttributes("attributes");
Expresion criteria = attributes.get("_name").equal(record.getParameter("name"));
criteria = criteria.and(attributes.anyOf("_values").equal(record.getParameter("value")))

This query can be added as a named query through a SessionCustomizer by calling the addQuery(name, query) method.

That is the basics of how it should look. With a little massaging of the code, it should be possible to use this query just like any other named query in JPA.

BTW: Here is the Customizer doc:


Daniel.Stucky@xxxxxxxxxxx wrote:
Hi all,

given the following Entities, how can I express a named query that
selects all Records where AttributeDao._name = "X" and

@Table(name = "RECORDS")
public class RecordDao implements Serializable {

  @Column(name = "ID")
  private String _idString;

  @Column(name = "SOURCE")
  private String _source;

@Table(name = "ATTRIBUTES")
public class AttributeDao {

  @Column(name = "ATT_ID")
  private String _id;
@Column(name = "ATT_NAME")
  private String _name;

  @BasicCollection (
    @CollectionTable (
) private List<String> _values;

I tried something like this

      query="SELECT DISTINCT r FROM RecordDao r JOIN r._attributes a
JOIN a._values v WHERE a._name = :name AND v._values = :value")


but during EntityManager creation I get the following error:

Exception [EclipseLink-8030] (Eclipse Persistence Services - 1.0.2
(Build 20081024)): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query
[RecordDao.findByAttribute: SELECT DISTINCT r FROM RecordDao r JOIN
r._attributes a JOIN a._values v WHERE a._name = :name AND v._values =
:value], line 1, column 63: unknown state or association field [_values]
of class [org.eclipse.smila.datamodel.persistence.AttributeDao].

I expect the syntax for "AND v._values = :value" to be not valid, but I
wonder why it complains about JOIN a._values v.
Anyone any ideas/suggestions ?

eclipselink-users mailing list

Back to the top