0

I have this code:

        Session session = HibernateUtil.createSessionFactory().openSession();
        Transaction tx = null;
        
        String hql = "from Person";
        Query query = session.createQuery(hql);
        
        List<Person> persons = null;
        

        try {
            tx = session.beginTransaction();
                    
                persons = query.list();
            
            tx.commit();
        } 
        catch (HibernateException e) {
            if (tx != null) {
                tx.rollback();
            }
            System.out.println(e);
        } finally {
            HibernateUtil.close();
        }
        
        for(Person person : persons){
            System.out.println(person);
        }
    }

and it prints this in the console:

Hibernate: select person0_.person_id as person_i10, person0_.address as address20, person0_.age as age30, person0_.name as name40 from person person0_
main.Person@1518f37
main.Person@12a01d4
Feb 09, 2021 10:30:48 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
main.Person@692d67
main.Person@f5c518
main.Person@148b3d2

How can I parse this output to be readable? I am using a SQL database with one table and 4 columns in that table. The input into the database works fine, and data is readable in MySQL workbench using query.

DanisJa
  • 13
  • 4

1 Answers1

0

Do you mean the lines with main.Person@148b3d2? What is the default toString() version of your object. If you want a better representation, you need to override the toString() method of your Person.

See this question for more details on how to do that: How to override toString() properly in Java?

seism0saurus
  • 396
  • 2
  • 10