java - JPQL Query a list of Strings inside an Entity -


i'm using java ee7 glassfish 4.1 server build system can post ideas, , each idea may have tags. i've declared entity idea as:

@entity @table(name = "ideas") public class idea implements serializable {  // id, description, etc.  @elementcollection private list<string> tags;  // getters, setter, etc. } 

after reading jpa: query embeddable list inside entity tried find tag following way:

public list<idea> getideaswithtag(string tag) {     string querystr = "select ideatags idea "             + "inner join i.tags ideatags "             + "where ideatags.tags = :ptag";     object res = em.createquery(querystr)             .setparameter("ptag", tag)             .getresultlist();     return (list<idea>) res; } 

but i'm getting transactionrolledbacklocalexception caused by:

caused by: java.lang.illegalargumentexception: exception occurred while creating query in entitymanager: exception description: problem compiling [select ideatags idea inner join i.tags ideatags ideatags.tags = :ptag]. [61, 74] state field path 'ideatags.tags' cannot resolved valid type.

i appreciate help, in advance!!

you have problems query:

select ideatags  idea inner join i.tags ideatags ideatags.tags = :ptag 

you want result idea select list.

you list tags in ideatags, therefore cant attribute tag of ideatags.

if want search in list have use in.

you can try this:

select idea :ptag in (i.tags) 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -