Skip to main content

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

Hi all,

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


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

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

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

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

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  @Column(name = "ATT_ID")
  private String _id;
  
  @Column(name = "ATT_NAME")
  private String _name;

  @BasicCollection (
    fetch=FetchType.EAGER,
    valueColumn=@Column(name="ATT_VALUE"))
    @CollectionTable (
        name="ATTRIBUTE_VALUES",
        primaryKeyJoinColumns=
        {@PrimaryKeyJoinColumn(name="ATT_ID",
referencedColumnName="ATT_ID")}
    )    
  private List<String> _values;
...
}



I tried something like this

@NamedQueries({
    @NamedQuery(name="RecordDao.findByAttribute",
      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 ?


Bye,
Daniel


Back to the top