《hibernate中文参考》中,学习第一个例子
---hibernate.cft.xml---:
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
<property name="show_sql">false</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="/org/hibernate/examples/quickstart/Cat.hbm.xml"/>
</session-factory>
-----Cat.hbm.xml----
<class name="org.hibernate.examples.quickstart.Cat" table="CAT">
<id name="id" type="string" unsaved-value="null" >
<column name="CAT_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name">
<column name="NAME" length="16" not-null="true"/>
</property>
<property name="sex"/>
<property name="weight"/>
</class>
---用的mysql4.1,手动建quickstart库,建cat表,cat表的字段是这样定义的:--
cat_id char(32) not null
name char(16) not null
sex char(1)
weight float
报错:java.lang.ExceptionInInitializerError
org.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:19)
com.struts.cat.action.InsertAction.execute(InsertAction.java:23)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1158)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
我想可能是数据库建的有问题,因为都是照抄的,请各位高人指点。
------解决方法--------------------------------------------------------
好象是找不到你的配注文件呢,
sessionFactory = new Configuration().configure().buildSessionFactory();
我是直接这样建的,把配置文件放到class目录下!!
------解决方法--------------------------------------------------------
hibernate.cft.xml ==>hibernate.cfg.xml