Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate help me write query
    primarykey
    data
    text
    <p>Im making an email client in java. When user creates mail with attachment(document), it saves all the data about email message in database but in multiple tables, like attachement title in Document_table.title, number of message in msgnumber.num, date in msgnumber.date, name of sender in Official_Person.name and OfficialPerson.secondname. How do i retrieve all this data and display it (im using Jtable for this)? I know how to get data if it saved in one table but not multiple. please help me.</p> <p>one format has many documnets.</p> <p>DOCUMENT:</p> <pre><code>@Entity @Table(name="DOCUMENT" ,schema="Default" ) public class Document implements java.io.Serializable { @ManyToOne @JoinColumn(name = "FormatID") private Format format; @Id @Column(name = "DocumentID", unique = true, nullable = false) private int documentId; </code></pre> <p>FORMAT :</p> <pre><code>@Entity @Table(name="FORMAT" ,schema="Default" ) public class Format implements java.io.Serializable { @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "FormatID") private Set&lt;Document&gt; documents = new HashSet(); @Id @Column(name = "FormatID", unique = true, nullable = false) private int formatId; </code></pre> <p>format.hbm</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="entity2.Format" table="FORMAT"&gt; &lt;id name="formatId" type="int"&gt; &lt;column name="FormatID" length="2000000000" /&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;set name="documents" table="DOCUMENT" inverse="true" lazy="true" fetch="select"&gt; &lt;key&gt; &lt;column name="FormatID" not-null="true" /&gt; &lt;/key&gt; &lt;one-to-many class="entity2.Document" /&gt; &lt;/set&gt; </code></pre> <p>document.hbm</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="entity2.Document" table="DOCUMENT"&gt; &lt;id name="documentId" type="int"&gt; &lt;column name="DocumentID" length="2000000000" /&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;many-to-one name="format" class="entity2.Format" fetch="select"&gt; &lt;column name="FormatID" not-null="true" /&gt; &lt;/many-to-one&gt; </code></pre> <p>i want to retrieve all documents for format 1:</p> <pre><code>Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Format f = (Format) session.get(Format.class, 1); System.out.println(f.getName()); System.out.println(f.getDocuments()); </code></pre> <p>documents is empty? where am i wrong?</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. 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