0

In this method i used SessionFactory.openSession() to get hibernate Session :

public static Session getSession() {
    Session session = null;
    if (factory == null) {
        session = initSessionFactory().openSession(); //initSessionFactory() returns SessionFactory object.
    } else {
        session = factory.openSession();
    }
    return session;
}

since, the method SessionFactory#openSession() throws HibernateException, then why doesn't my method throw an Exception, why there is not any CompileTime Error?

amit bhardwaj
  • 883
  • 2
  • 8
  • 18
  • You use openSession to get a Session? I use openSession to **open** a Session! And i use **getSession** to get a Session. (your factory is always `null`?) ;D – Grim May 06 '14 at 12:34

4 Answers4

4

HibernateException extends RuntimeException.

sp00m
  • 47,968
  • 31
  • 142
  • 252
2

Because HibernateException is RuntimeException just like NullPointerException

Inheritance hierarchy is

RuntimeException -> NestedRuntimeException -> HibernateException

Vinay Lodha
  • 2,185
  • 20
  • 29
0

HibernateException inherits from RuntimeException. You don't have to catch or declare RuntimeExceptions.

See RuntimeExceptions

BetaRide
  • 16,207
  • 29
  • 99
  • 177
0

HibernateException extends RuntimeException, therefore making it an unchecked exception.

Unchecked exceptions don't need to be caught

Community
  • 1
  • 1
renz
  • 1,072
  • 3
  • 11
  • 21