Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you are working with JPA, you should think Object and relations between Objects and you should map your Object model, not <code>ids</code>, to your relational model (it is possible to map a <code>List</code> of basic values with <a href="http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection" rel="nofollow noreferrer"><code>@ElementCollection</code></a> in JPA 2.0 though but what I said just before still applies).</p> <p>Here, (assuming this really is a <strong>one-to-many</strong> relation between <code>Message</code> and <code>GroupAssoc</code> and not a <strong>many-to-many</strong> relation between <code>Message</code> and <code>Group</code> entities) you should have something like this:</p> <pre><code>@Entity @Table(name = "MESSAGE") public class Message implements Serializable { @Id @Column(name = "MESSAGE_ID") @GeneratedValue(strategy = GenerationType.IDENTITY) private Long messageId; @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST) private List&lt;GroupAssoc&gt; groupAssocs = new ArrayList&lt;GroupAssoc&gt;(); public Long getMessageId() { return messageId; } public void setMessageId(Long messageId) { this.messageId = messageId; } public List&lt;GroupAssoc&gt; getGroupAssocs() { return groupAssocs; } public void setGroupAssocs(List&lt;GroupAssoc&gt; groupAssocs) { this.groupAssocs = groupAssocs; } // equals() and hashCode() } </code></pre> <p>And another entity for <code>GroupAssoc</code>.</p> <p>PS: Your DDL really looks like a (M:N) relation between <code>MESSAGE</code> and <code>GROUP</code> (or I don't understand the PK constraint of <code>GROUP_ASSOC</code>) but you didn't show any FK constraint on <code>GROUP_ID</code> so I'm not 100% sure. But if that's the case, then you should use an <code>@ManyToMany</code> instead of <code>@OneToMany</code>.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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