I'm working on a project with Hibernate now but I get an error when running my project.
On server.java (my entry point) I got this:
private static HibernateUtil hibernateUtil;
And in my entry point:
hibernateUtil = new HibernateUtil();
This is my HibernateUtil class:
public class HibernateUtil { private SessionFactory sessionFactory; public HibernateUtil() { StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); try { sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory(); } catch (Exception e) { StandardServiceRegistryBuilder.destroy( registry ); } } public SessionFactory getSessionFactory() { return sessionFactory; }}
Now my Hibernate.cf.xml:
<hibernate-configuration><session-factory><property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">123</property><property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dynamicdb</property><property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property><property name="show_sql">false</property> <property name="connection.pool_size">1</property></session-factory>
And now this is the error I get:
Jun 18, 2016 1:17:17 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.0.Final} Jun 18, 2016 1:17:17 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Jun 18, 2016 1:17:17 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Jun 18, 2016 1:17:18 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/dynamicdb] Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001001: Connection properties: {user=root, password=****} Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001003: Autocommit mode: false Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init> INFO: HHH000115: Hibernate connection pool size: 1 (min=1) Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/dynamicdb] Jun 18, 2016 1:17:18 PM org.hibernate.service.internal.AbstractServiceRegistryImpl stopService INFO: HHH000369: Error stopping service [class org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] : java.lang.NullPointerException
I'm running Eclipse mars 2 on Mac OS X 10.10 with MAMP. MySQL is running and the database user and database exists and the password is correct. What's the problem?