Answer the question
In order to leave comments, you need to log in
Why is Session Factory null?
I am getting Session Factory null ?? Why ? What am I doing wrong ?
configuration class:
public class SessionManager {
public static SessionFactory configure(){
return new Configuration().configure("hibernate.cfg.xml") // 9 line
.buildSessionFactory();
}
}
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>
Answer the question
In order to leave comments, you need to log in
Imho either does not find the configuration file, or some rubbish is written in it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question