| 发表于:2008-01-07 11:09:41 楼主 |
各位大侠,这几天按照网上的介绍,在eclpse环境里面,作了个简单的hibernate例子,运行,但是报错:java.lang.exceptionininitializererror,具体的代码以及配置文件如下: hibernate.cfg.xml配置内容: <?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"> <!-- generated by myeclipse hibernate tools. --> <hibernate-configuration> <session-factory> <property name="connection.username"> cbs </property> <property name="connection.url"> jdbc:oracle:thin:@localhost:1521:cbstj </property> <property name="dialect"> net.sf.hibernate.dialect.oracledialect </property> <property name="jdbc.fetch_size"> 50 </property> <property name="jdbc.batch_size"> 25 </property> <property name="show_sql"> true </property> <property name="use_outer_join"> false </property> <property name="connection.password"> admin </property> <property name="connection.driver_class"> oracle.jdbc.driver.oracledriver </property> <mapping resource="tregister.hbm.xml"/> </session-factory> </hibernate-configuration> tregister.hbm.xml的内容: <?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- mapping file autogenerated by myeclipse - hibernate tools --> <hibernate-mapping> <class name="hibernate.po.tregister" table="t_register"> <id name="id" type="java.lang.integer"> <column name="id" /> <generator class="increment" /> </id> <property name="username" type="java.lang.string"> <column name="username" length="30" /> </property> <property name="userpwd" type="java.lang.string"> <column name="userpwd" length="30" /> </property> <property name="sex" type="java.lang.string"> <column name="sex" length="10" /> </property> <property name="age" type="java.lang.integer"> <column name="age" /> </property> </class> </hibernate-mapping> 配置文件都放在classes下面。 hibernateutil.java获取唯一session实例: package hibernate; import org.hibernate.hibernateexception; import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.cfg.configuration; public class hibernateutil{ private static final sessionfactory sessionfactory; static { try { configuration config = new configuration().configure("/hibernate.cfg.xml"); sessionfactory = config.buildsessionfactory(); } catch(throwable e) { system.out.println("exceptionininitializererror----------" ); throw new exceptionininitializererror(e); } } public static final threadlocal session = new threadlocal(); public static session currentsession() throws hibernateexception { session s = (session)session.get(); //open a new session,if this thread has none yet if(s == null ¦ ¦ !s.isopen()) { s = sessionfactory.opensession(); session.set(s); } return s; } public static void closesession() throws hibernateexception { session s = (session)session.get(); session.set(null); if(s != null) s.close(); } } 当运行到:sessionfactory = config.buildsessionfactory()时,就报上面那个错java.lang.exceptionininitializererror。 我在工程的lib下面,我把hibernate-3.2.5.ga.tar.gz里面的jar都已经放进去(包括hibernate3.jar),构建路径当然也已经指向\web-inf\lib了,但是还是报错,是什么原因呢? |
|
|
|
|