hibernate配置文件:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property>
        <property name="connection.username">scott</property>
        <property name="connection.password">tiger</property>        <!-- JDBC connection pool (use the built-in) -->
        <!--
        <property name="connection.pool_size">1</property>        -->
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>        <!-- Enable Hibernate's automatic session context management -->
        <!--<property name="current_session_context_class">thread</property>-->        <!-- Disable the second-level cache  -->
        <!--<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>-->        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>        <mapping resource="com/alexander/model/Student.hbm.xml"/>
<!--<mapping class="com.bjsxt.hibernate.Teacher"/>-->
    </session-factory></hibernate-configuration>domain object 配置:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.alexander.model">
<class name="com.alexander.model.Student" table="t_student">
<id name="id" />
<property name="name" />
    </class>

</hibernate-mapping>测试代码:
public static void main(String[] args) {
Student s = new Student(001,"star");
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sessionFactory.close();

}错误信息:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.alexander.test.Demo.main(Demo.java:13)
Caused by: java.lang.NullPointerException
at org.slf4j.LoggerFactory.singleImplementationSanityCheck(LoggerFactory.java:192)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:113)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
... 1 more谢谢你的浏览

解决方案 »

  1.   

    at com.alexander.test.Demo.main(Demo.java:13)
    Caused by: java.lang.NullPointerExceptionmain函数中的13行空指针!
      

  2.   

    你都把工厂给关了,肯定是有null异常
      

  3.   

    为什么配置文件中驱动是用的mysql,但是url却是用oracle的呢?property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property>
      <property name="connection.username">scott</property>
      <property name="connection.password">tiger</property>
    你换个oracle驱动试试!!!
      

  4.   

    [Quote=引用 2 楼 yinbaicheng 的回复:]
    at com.alexander.test.Demo.main(Demo.java:13)
    Caused by: java.lang.NullPointerExceptionmain函数中的13行涉及到的对象都有可能是null对象,可以用打印的方式来检查一下!
      

  5.   

     <property name="connection.driver_class">com.mysql.jdbc.Driver</property>//这里是mysql
      <property name="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property>//这里是oracle
    老大你这2个地方不一样啊,你同时搞了2个不同的数据库
      

  6.   

    用了mysql的jdbc  完了之后指定了oracle的url  最后指定了oracel的方言