Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Manning book <a href="http://www.manning.com/bauer2/" rel="noreferrer">Java Persistence with Hibernate</a> has an example outlining how to do this in Section 7.2. Fortunately, even if you don't own the book, you can see a source code example of this by downloading the JPA version of the <a href="http://downloads.jboss.org/hibernate/caveatemptor/" rel="noreferrer">Caveat Emptor</a> sample project (direct link <a href="http://downloads.jboss.org/hibernate/caveatemptor/caveatemptor-jpa-061211.zip" rel="noreferrer">here</a>) and examining the classes <code>Category</code> and <code>CategorizedItem</code> in the <code>auction.model</code> package.</p> <p>I'll also summarize the key annotations below. Do let me know if it's still a no-go.</p> <p>ParentObject:</p> <pre><code>@Entity public class ParentObject { @Id @GeneratedValue @Column(name = "parentId", nullable=false, updatable=false) private Long id; @OneToMany(mappedBy="parent", fetch=FetchType.EAGER) @IndexColumn(name = "pos", base=0) private List&lt;ObjectChild&gt; attrs; public Long getId () { return id; } public List&lt;ObjectChild&gt; getAttrs () { return attrs; } } </code></pre> <p>ChildObject:</p> <pre><code>@Entity public class ChildObject { @Embeddable public static class Pk implements Serializable { @Column(name = "parentId", nullable=false, updatable=false) private Long objectId; @Column(nullable=false, updatable=false) private String name; @Column(nullable=false, updatable=false) private int pos; ... } @EmbeddedId private Pk id; @ManyToOne @JoinColumn(name="parentId", insertable = false, updatable = false) @org.hibernate.annotations.ForeignKey(name = "FK_CHILD_OBJECT_PARENTID") private ParentObject parent; public Pk getId () { return id; } public ParentObject getParent () { return parent; } } </code></pre>
 

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