Note that there are some explanatory texts on larger screens.

plurals
  1. POEJB JPA QL. Need query to get data from DB by element in Collection object
    primarykey
    data
    text
    <p>I am facing a proble that put me in difficult situation. I have class Article:</p> <pre><code> @Entity @Table(name = "Articles") public class Article implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="article_id") private Long id; @Column(name="a_name") private String name; @Column(name="a_content") private String content; @OneToMany @Column(name="a_tag") private Collection &lt;Tags&gt; tag; @Entity @Table(name = "Tags") public class Tags implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="tag_id") private Long tag_id; @Column(name="tag_name",nullable=false) private String tag_name; @Column(name="tag_descr") private String tag_descr; //position 0 - supertag //position 1 - subsupertag //position 2 - subtags //Collection limited to 3 elements.(3 tags at most, necessaryly Super,subsuper,subtag @Column(name="super_tags") @OneToMany private Collection&lt;Tags&gt; supertags = new ArrayList&lt;Tags&gt;(3); //0-supertag 1-subsupertag 2- subtags @Column(name="tag_type") private int tag_type; </code></pre> <p>My tagging system is such that I have Supertag, subsuprttag and subtag. Supertag is parent for subsupertag and subtag, subsupertag is parent for subtag. Each article has super, subsuper and sub tags.</p> <p>Now, I want to get only articles from database, that has a certain tag, but have no idea how to refere to , for example, element 2 in Collection tags (by name or position), (which would be subtag). </p> <pre><code>final String q = "SELECT f FROM Article f WHERE f.a_tag= ..I m lost here ... EntityManager em; em.createQuery(q).getResultList(); </code></pre> <p>I hope my question is clear enough. I gave it my best shot)) Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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