Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6825851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:04:47+00:00 2026-05-26T22:04:47+00:00

Im making an email client in java. When user creates mail with attachment(document), it

  • 0

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.

one format has many documnets.

DOCUMENT:

@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;

FORMAT :

@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<Document> documents = new HashSet();

    @Id
    @Column(name = "FormatID", unique = true, nullable = false)
    private int formatId;

format.hbm

<hibernate-mapping>
    <class name="entity2.Format" table="FORMAT">
        <id name="formatId" type="int">
            <column name="FormatID" length="2000000000" />
            <generator class="native" />
        </id>
                <set name="documents" table="DOCUMENT"
                inverse="true" lazy="true" fetch="select">
            <key>
                <column name="FormatID" not-null="true" />
            </key>
            <one-to-many class="entity2.Document" />
        </set>

document.hbm

<hibernate-mapping>
    <class name="entity2.Document" table="DOCUMENT">
        <id name="documentId" type="int">
            <column name="DocumentID" length="2000000000" />
            <generator class="native" />
        </id>

        <many-to-one name="format" class="entity2.Format" fetch="select">
            <column name="FormatID" not-null="true" />
        </many-to-one>

i want to retrieve all documents for format 1:

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());

documents is empty? where am i wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:04:48+00:00Added an answer on May 26, 2026 at 10:04 pm

    If you define a relationship between classes, for example:

    class Person {    
       @OneToMany(cascade=CascadeType.ALL,
                  fetch= FetchType.EAGER)
       private Set<Email> emails = new HashSet();
    
       // getters/setters and some other attributes are not shown
    

    When you read an object from the database, you will get another object that has a relationship with it automatically.

    Session s = HibernateUtil.getSessionFactory().openSession();
    Person p = (Person) s.get(Person.class, 1);
    s.close();
    
    System.out.println(p.getName());
    System.out.println(p.getEmails());
    

    The following is an example of bidirectional one to one relationship.

    class Person {
        @OneToOne(cascade=CascadeType.ALL)
        private Address address;
    
    
    class Address {
        @OneToOne(mappedBy=”address”)
        private Person person
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a database of my client's customers to send email promotions to.
I am new to android development . I am making a small email client
I am making a simple email application in Java. I have an Account class.
I am trying to make a simple email client in Java Swing. I want
Making an adobe flex ui in which data that is calculated must use proprietary
Im making a login/logout class that logs users in, sets cookies based on user's
So I am making an app where one is able to enter client info
I'm making an email sending program and still I don't know how to check
I need to attach a file to the email Magento sends when a client
I've got two servers on two locations. Server 1 subtracts client-information (like addresses, email

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.