<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- 通常,一个session-factory节点代表一个数据库 -->
<session-factory>
<!-- 1. 数据库连接配置 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/framwork?useUnicode=true&characterEncoding=UTF-8</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!--
数据库方法配置, hibernate在运行的时候,会根据不同的方言生成符合当前数据库语法的sql
-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- 2. 其他相关配置 -->
<!-- 2.1 显示hibernate在运行时候执行的sql语句 -->
<property name="hibernate.show_sql">true</property>
<!-- 2.2 格式化sql
<property name="hibernate.format_sql">true</property> -->
<!-- 2.3 自动建表 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 3. 加载所有映射
<mapping resource="cn/itcast/a_hello/Employee.hbm.xml"/>
-->
<mapping resource="cn/itcast/b_one2Many/Dept.java"/>
<mapping resource="cn/itcast/b_one2Many/Employee.java"/>
</session-factory>
</hibernate-configuration>
这里如果写<mapping>
就会报java.lang.ExceptionInInitializerError
可是用开发模式就可以
atic {
sf = new Configuration().configure("hibernate.cfg.xml")
.addClass(Dept.class)
.addClass(Employee.class) // 测试时候使用
.buildSessionFactory();
求解决
这个你最好吧你建session的代码贴出来,我貌似遇到过这个问题,正常是使用classpathxml获取session的吧,这种方式需要有事务支持,而直接用huild好像不用,关键你一定确保你事务正常开启了
就是你session创建方式需要注意
哥,你的映射加载了java文件了,应该是xml文件的