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

  • SEARCH
  • Home
  • 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 277997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:10:04+00:00 2026-05-12T01:10:04+00:00

i ‘m trying the hibernate tutorials from their main site and wanted to change

  • 0

i ‘m trying the hibernate tutorials from their main site and wanted to change thing a bit to know how many to many relationship work with java.util.set interface.My mappings are correct and i can insert in and from the tables EVENT, PERSON and the mapping table PERSON_EVENT.Now i’ve inserted some dummy values in the tables and add their mappings in the mapping table.I wanted to display all the events of all the person who are register to an event or more. with this code :

 public void ShowPersonEvents()
 {
     Person aperson;
     Event anEvent;
     Session session = HibernateUtil.getSessionFactory().getCurrentSession();
     session.beginTransaction();
     List<Person> persons = session.createQuery("from Person").list();
     for(int i =0; i< persons.size(); i++)
     {
         aperson = (Person) persons.get(i);
         Set a = aperson.getEvents();
//            String[] events = (String[])a.toArray(new String[a.size()]);
//             for (String e : events)
//             {
//                 System.out.println(aperson.getLastname()+" is registerd to the" + e);
//
//             }
         Iterator it = a.iterator();
         while(it.hasNext())
         {
             System.out.println(aperson.getLastname()+" is registerd to the" +(String) it.next().toString());
         }

//                System.out.println();
         }
         session.getTransaction().commit();
     }
}

so when i run is the who the correct number of rows but instead of show for example rows like :

Joseph is registered to the opensouce event

it’s rather showing something like :

Joseph is registered to the domain.Event@18a8ce2

this is the format mypackagename.myclassname@something.
when i comment the iterator part ant uncomment the casting to an string array i have an exception:arraystoreexception.
I’m kind of lost a bit.I can’t see what is wrong here.Please can you have a look and tell me what i did wrong?Thanks for reading.

  • 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-12T01:10:05+00:00Added an answer on May 12, 2026 at 1:10 am

    This doesn’t really have anything to do with Hibernate. You’re calling toString() on the Event object:

    (String) it.next().toString()
    

    You haven’t overridden the Event.toString() method, so you’re getting the default implementation. Instead try something like:

    while(it.hasNext()) {
        Event event = (Event) it.next();
        System.out.println(aperson.getLastname()+" is registerd to the" + event.getName());
    }
    

    You can also improve your Hibernate HQL query by pre-fetching the events. As it stands now they will be lazy loaded so you’ll get an extra query for each person (assuming you haven’t set the fetching strategy in the mapping file).

    Try something like:

    List<Person> persons = session.createQuery("from Person p left join fetch p.events").list();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
I am trying to create a RegEx expression that will successfully parse the following
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I was writing code for dragging mechanism which invokes to wait for small period

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.