Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPA2 ElementCollection quering

Is the behavior any different when you specify the persistence unit property:

eclipselink.jpql.parser=eclipselink.jpql.parser

On 30/01/2013 7:35 AM, Jiri Pejsa wrote:
Hello,

I am momentarily working on the project, where we are using Eclipselink as JPA
provider. The project is JaveEE application runing on Glassfish 3.1.2.2, Java7
and Eclipselink 2.4.0.

I have entity with collections of tags and I need read the entity by list of its
tags. Pure SQL query is something like this:

SELECT e.* FROM entity e JOIN tags t ON t.entity_id = e.id
WHERE t.tag in ('foo','bar').

My Entity looks like this:
@Entity
publi class Shortcode {
....
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "shortcode_groups")
@Column(name = "sc_group")
private List<String> groups;
....
}

next I have Stateless EJB where I define method to reading this shortcodes:

@Override
@SuppressWarnings("unchecked")
public List<Shortcode> findAllByGroups(List<String> groups) {
if (groups != null && !groups.isEmpty())
     return em.createQuery("SELECT s FROM Shortcode s WHERE s.groups IN
:groups", Shortcode.class).setParameter("groups", groups).getResultList();
else
     return Collections.emptyList();
}

and this method i called by:
List<Shortcode> shortcodes =
shortcodeService.findAllByGroups(Arrays.asList("cz", "903"));

This should work
(http://stackoverflow.com/questions/2772305/jpql-in-clause-java-arrays-or-lists-sets)
and select all Shortcodes with "tags" 'cz' and '903'. But calling method
shortcodeService.findAllByGroups(Arrays.asList("cz", "903")) throw an exception:


Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services -
2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT s FROM Shortcode s WHERE
s.groups IN :groups].
[32, 40] The state field path 's.groups' cannot be resolved to a collection type.

And I dont know what is wrong on this approach. How can I find Shortcodes by
collections on "group" ?

I look forward to hearing from you.

Jiri
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top