ich einen Null-Zeiger auf Linie bekommen 15 ... unten (Session session = HibernateUtil.getSessionFactory.getCurrentSession();)Hibernate Null-Zeiger
public static void main(String[] args) {
// TODO Auto-generated method stub
HibernateUtil.buildSessionFactory();
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
User u = new User();
u.setEmail("[email protected]");
u.setFirstName("David");
u.setLastName("Gray");
session.save(u);
session.getTransaction().commit();
System.out.println("Record committed");
session.close();
Mein HibernateUtil ist wie folgt ...
Off Thema, aber wenn jemand auch eine Standard-Transaktion Winterschlaf Utils könnte sie empfehlen, dass wäre ace. Aber ich kann nicht sehen, warum ich die Nullpointer bekommen, scheint die hibernate.cfg.xml fein zu validieren, wie die Protokolle sagen, dass es an die DB usw. anschließen könnte
INFO : org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
INFO : org.hibernate.Version - HHH000412: Hibernate Core {4.1.0.Final}
INFO : org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
INFO : org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
INFO : org.hibernate.cfg.Configuration - HHH000043: Configuring from resource: /hibernate.cfg.xml
INFO : org.hibernate.cfg.Configuration - HHH000040: Configuration resource: /hibernate.cfg.xml
WARN : org.hibernate.internal.util.xml.DTDEntityResolver - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
INFO : org.hibernate.cfg.Configuration - HHH000041: Configured SessionFactory: null
INFO : org.hibernate.cfg.Configuration - HHH000043: Configuring from resource: /hibernate.cfg.xml
INFO : org.hibernate.cfg.Configuration - HHH000040: Configuration resource: /hibernate.cfg.xml
WARN : org.hibernate.internal.util.xml.DTDEntityResolver - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
INFO : org.hibernate.cfg.Configuration - HHH000041: Configured SessionFactory: null
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000402: Using Hibernate built-in connection pool (not for production use!)
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 1
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000006: Autocommit mode: false
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/assessme]
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000046: Connection properties: {user=root, password=****}
INFO : org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
INFO : org.hibernate.engine.transaction.internal.TransactionFactoryInitiator - HHH000399: Using default transaction strategy (direct JDBC transactions)
INFO : org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
INFO : org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000228: Running hbm2ddl schema update
INFO : org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000102: Fetching database metadata
INFO : org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000396: Updating schema
INFO : org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000232: Schema update complete
Danke, ich scheine eine "unbekannte Entität" Ausnahme auf Benutzer zu bekommen, aber ich habe es als @Entity irgendwelche Ideen kommentiert? – david99world
Kein Problem. Einige mögliche Lösungen für Ihre unbekannte Entity-Ausnahme finden Sie unter [diese SO-Frage] (http://stackoverflow.com/questions/270074/hibernate-jpa-annotations-unknown-entity). –