Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have a many-to-many relationship between your songs and keywords.<br> I believe your query should be <code>select p from Playlist p, Songs s where p.user = :user and s.keywords member of p.keywords</code> although I'm not 100% sure you can do a <code>member of</code> operation between two collections. You might have to use a subquery to grab all the <code>p.keywords</code> and the <code>ANY</code> expression to do that. See <a href="http://download.oracle.com/docs/cd/E11035_01/kodo41/full/html/ejb3_langref.html#ejb3_langref_collection_member" rel="nofollow noreferrer">this article</a> for more.</p> <p>After your answer, I realized that a playlist was not the list of songs you're getting from the JPQL. You're trying to get a field set in the playlist object.</p> <p>If you're thinking that JPA is just an easy way to do DB work. You're sorta right. You can't really do what I believe your doing in any OO language. You can't define a field as the result of a query.</p> <p>What you can do, however is get the playlist definition from the user, name, and keywords that are part of the playlist. Then run a query looking for songs with those keywords, and then in java do something like <code>curPlaylist.addAll( queryResult); em.merge(curPlaylist);</code>. This assumes that you have your cascades set right of course. Now, when you get the playlist from the entity manager, you'll also pull back the playlist. </p> <p>If your looking for something more dynamic, where the list is automatically updated, then you can run the query every time you need a list matching the playlist criteria.</p>
 

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