0

I need to Print actual value from below list of objects. Is this possible to get actual values from this list ?

try {

        Session session = factory.getCurrentSession();

        session.beginTransaction();
        Query query = session.createQuery("select uName1,pass1 from UserRegModel");

        List<Object> userList = new ArrayList<Object>();

        userList = query.getResultList();

        System.out.println("selecting usernaem and pass done");

        for (Object temp : userList) {

            System.out.println(temp);
        }

        session.getTransaction().commit();

        return userList;

    } catch (Exception e) {
        System.out.println(e);
    }

I get below output. not the actual password and username

Ljava.lang.Object;@2c36b22d

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
user8048032
  • 145
  • 1
  • 1
  • 8
  • usr getters on the object to get the uname/passwd(recommended way) or override the `toString()` method to print them, when directly using object(not recommended) – Amit Jun 04 '17 at 08:50
  • 1
    Override `toString()` in the `UserRegModel` class and as a side note you should also use a more specific type than `Object` in the declared `List`. You manipulate list of `UserRegModel`. So declare : `List`. – davidxxx Jun 04 '17 at 08:50
  • Possible duplicate of [Trying to display contents of ArrayList. Getting \[Ljava.lang.String;@232204a1](https://stackoverflow.com/questions/32900426/trying-to-display-contents-of-arraylist-getting-ljava-lang-string232204a1) – KevinO Jun 04 '17 at 08:55
  • Duplicate of: https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4 – KevinO Jun 04 '17 at 08:56

0 Answers0