问题描述
hibernate配置文件:<?xmlversion='1.0'encoding='utf-8'?><!DOCTYPEhibernate-configurationPUBLIC"-//Hibernate/HibernateConfigurationDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><!--Databaseconnectionsettings--><propertyname="connection.driver_class">com.mysql.jdbc.Driver</property><propertyname="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property><propertyname="connection.username">scott</property><propertyname="connection.password">tiger</property><!--JDBCconnectionpool(usethebuilt-in)--><!--<propertyname="connection.pool_size">1</property>--><!--SQLdialect--><propertyname="dialect">org.hibernate.dialect.OracleDialect</property><!--EnableHibernate'sautomaticsessioncontextmanagement--><!--<propertyname="current_session_context_class">thread</property>--><!--Disablethesecond-levelcache--><!--<propertyname="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>--><!--EchoallexecutedSQLtostdout--><propertyname="show_sql">true</property><!--Dropandre-createthedatabaseschemaonstartup--><propertyname="hbm2ddl.auto">update</property><mappingresource="com/alexander/model/Student.hbm.xml"/><!--<mappingclass="com.bjsxt.hibernate.Teacher"/>--></session-factory></hibernate-configuration>domainobject配置:<?xmlversion="1.0"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mappingpackage="com.alexander.model"><classname="com.alexander.model.Student"table="t_student"><idname="id"/><propertyname="name"/></class></hibernate-mapping>测试代码:publicstaticvoidmain(String[]args){Students=newStudent(001,"star");SessionFactorysessionFactory=newConfiguration().configure().buildSessionFactory();Sessionsession=sessionFactory.openSession();session.beginTransaction();session.save(s);session.getTransaction().commit();session.close();sessionFactory.close();}错误信息:Exceptioninthread"main"java.lang.ExceptionInInitializerErroratcom.alexander.test.Demo.main(Demo.java:13)Causedby:java.lang.NullPointerExceptionatorg.slf4j.LoggerFactory.singleImplementationSanityCheck(LoggerFactory.java:192)atorg.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:113)atorg.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)atorg.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)atorg.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)atorg.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)...1more谢谢你的浏览
解决方案
解决方案二:
表没有主键,报错的原因是空指针,13行,自己好好查查吧,这个错误别人不容易给你找出来,帮你顶一下。
解决方案三:
atcom.alexander.test.Demo.main(Demo.java:13)Causedby:java.lang.NullPointerExceptionmain函数中的13行空指针!
解决方案四:
你都把工厂给关了,肯定是有null异常
解决方案五:
为什么配置文件中驱动是用的mysql,但是url却是用oracle的呢?propertyname="connection.driver_class">com.mysql.jdbc.Driver</property><propertyname="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property><propertyname="connection.username">scott</property><propertyname="connection.password">tiger</property>你换个oracle驱动试试!!!
解决方案六:
[Quote=引用2楼yinbaicheng的回复:]atcom.alexander.test.Demo.main(Demo.java:13)Causedby:java.lang.NullPointerExceptionmain函数中的13行涉及到的对象都有可能是null对象,可以用打印的方式来检查一下!
解决方案七:
<propertyname="connection.driver_class">com.mysql.jdbc.Driver</property>//这里是mysql<propertyname="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property>//这里是oracle老大你这2个地方不一样啊,你同时搞了2个不同的数据库
解决方案八:
引用6楼hejun19860620的回复:
<propertyname="connection.driver_class">com.mysql.jdbc.Driver</property>//这里是mysql<propertyname="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property>//这里是oracle老大你这2个地……
用了mysql的jdbc完了之后指定了oracle的url最后指定了oracel的方言