Я получаю Session Factory null ?? Почему ? Что я делаю нетак ?
Configuration class:
public class SessionManager {
public static SessionFactory configure(){
return new Configuration().configure("hibernate.cfg.xml") // 9 line
.buildSessionFactory();
}
}
Main:
SessionFactory sessions = SessionManager.configure(); // 18 line
Session session = sessions.openSession();
session.getTransaction().begin();
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.boot.cfgxml.spi.LoadedConfig.consume(LoadedConfig.java:123)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:62)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at coupon.connection.SessionManager.configure(SessionManager.java:9)
at CouponSystemTesting.main(CouponSystemTesting.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernatedemo</property>
<property name="connection.username">root</property>
<property name="connection.password">****</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping class="coupon.entities.Company"/>
<mapping class="coupon.entities.Customer"/>
<mapping class="coupon.entities.Coupon"/>
<mapping class="coupon.entities.User"/>
<mapping class="coupon.entities.Role"/>
<mapping class="coupon.entities.Listener"/>
<mapping class="coupon.entities.Administrator"/>
<listener class="coupon.listeners.CompanyListener"/>
<listener class="coupon.listeners.CustomerListener"/>
</session-factory>
</hibernate-configuration>