67,549
社区成员




Could not parse configuration: /hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory >
<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:db2://localhost:50000/dvd</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="hibernate.connection.username">db2admin</property>
<property name="hibernate.connection.password">123456</property>
<!-- property name="hibernate.connection.pool_size"></property -->
<!-- dialect for DB2 -->
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!--
<property name="connection.characterEncoding">UTF-8</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hbm2ddl.auto">update</property>
-->
<mapping class="bean.Book"/><!-- bean包下有个Book类-->
<!--<mapping resource="bean/Book.hbm.xml"/>-->
</session-factory>
</hibernate-configuration>
private static final String CONFIG_PATH="/hibernate.cfg.xml";
private static final ThreadLocal threadLocal=new ThreadLocal();
private static final AnnotationConfiguration cfg=new AnnotationConfiguration();
private static SessionFactory sessionFactory=null;
public static Session currentSession(){
Session session=(Session) threadLocal.get();
if(session==null){
if(sessionFactory==null){
try{
cfg.configure(CONFIG_PATH);
sessionFactory=cfg.buildSessionFactory();
}catch(Exception e){
e.printStackTrace();
}
}
session=sessionFactory.openSession();
threadLocal.set(session);
}
return session;
}
<!-- 可以支持annotatedClasses -->
<property name="annotatedClasses">
<list>
<value>com.leeyas.common.model.Userinfo</value>
<value>com.leeyas.common.model.Book</value>
</list>
</property>