Ich arbeite jetzt an einem Projekt mit Hibernate, aber ich bekomme einen Fehler, wenn ich mein Projekt ausführen.Java Hibernate Throws Ausnahme beim Start
Auf server.java (mein Einstiegspunkt) habe ich dies:
private static HibernateUtil hibernateUtil;
Und in meinem Einstiegspunkt:
hibernateUtil = new HibernateUtil();
Das ist mein HibernateUtil Klasse:
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;
}
}
Jetzt mein 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>
Und jetzt dies ist der Fehler, den ich bekommen:
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
ich Eclipse-Mars 2 auf Mac OS X 10.10 mit MAMP renne. MySQL läuft und der Datenbankbenutzer und die Datenbank existieren und das Passwort ist korrekt. Was ist das Problem?
Definieren Sie einen Verbindungspool: http://www.mastertheboss.com/jboss-frameworks/hibernate-jpa/hibernate-configuration/configure-a-connection-pool-with-hibernate –
Mit: 'catch (Exception e) {StandardServiceRegistryBuilder.destroy (registry);} 'Sie können eine Ausnahme verbergen, die für das Debuggen nützlich sein könnte. Kannst du da wenigstens die Ausnahme melden? Der Nullpointer, den wir am Ende der Logs sehen, hat keinen Stacktrace? – Thierry
werfen Sie auch einen Blick auf diese Frage: http: // Stackoverflow.com/questions/16596528/hibernate-wowing-nullpointerexception – Thierry