I have a student table with the primary key id. I am using Hibernate and session's load command to fetch the record. The records I am fetching ids 1 and 2, are both not present in the database. I know that get() returns null in such cases and load() returns ObjectNotFoundException() in such cases. But I'm getting a strange output.
Student student1 = session.get(Student.class, 1);
System.out.println(student1);
Student student2 = session.load(Student.class, 2);
System.out.println("ABC");
System.out.println(student2);
The output I'm getting -
null
ABC
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.tutorial.Student#2]
The output I was expecting -
null
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.tutorial.Student#2]
Is there something I'm not getting here?