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谢谢你的浏览
<?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谢谢你的浏览
解决方案 »
- tomcat 服务器部署有web程序A 再不改变A的情况下,如何记录A的请求的头信息
- svn不能连接本地ip
- 高分求Struts2国际化程序
- 求sun.jdbc.rowset包和参考手册
- JBoss4下发布第一个EJB,有点不明白,请指点。
- 【Struts高难度】表单元素动态生成,怎么写struts-config.xml文件?【Struts高难度】
- weblogic 7.0 ejb 已发布 但客户端始终不能调用
- 谁能帮我学会解析XML文件800分相送
- 如下的j2ee命令都是什么意思啊
- 请问各位高手,有关BMP在weblogic上部署
- 获取文本框中的值
- 用代码执行和在查询器中执行返回的结果不一样????
Caused by: java.lang.NullPointerExceptionmain函数中的13行空指针!
<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驱动试试!!!
at com.alexander.test.Demo.main(Demo.java:13)
Caused by: java.lang.NullPointerExceptionmain函数中的13行涉及到的对象都有可能是null对象,可以用打印的方式来检查一下!
<property name="connection.url">jdbc:oracle:thin:@58.154.232.197:6666:ATHENA</property>//这里是oracle
老大你这2个地方不一样啊,你同时搞了2个不同的数据库