JBoss4 + Hibernate2 访问MySQL配置

类别:Java 点击:0 评论:0 推荐:

0、准备条件
   JBoss4数据库配置成功,参见http://blog.csdn.net/chenm《JBoss4安装配置》
   在$JBoss_home$/server/default/deploy下建立以下目录结构
                                     +---JavaTrip
                                           +---WEB-INF
                                                 +---classes
                                                 +---lib
1、Hibernate配置
1.1、将Hibernate的jar包拷贝到 $JBoss_home$/server/default/deploy/JavaTrip/WEB-INF/lib目录下:
        cglib-full-2.0.2.jar
  commons-collections-2.1.1.jar
  commons-logging-1.0.4.jar
  dom4j-1.4.jar
  ehcache-0.9.jar
  jta.jar
  log4j-1.2.8.jar
  odmg-3.0.jar
        hibernate2.jar
1.2、将hibernate.cfg.xml拷贝到 $JBoss_home$/server/default/conf, 设置数据库使用JBoss4的数据库连接。
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:/MySqlDS</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="Cat.hbm.xml"/>
</session-factory>

</hibernate-configuration>
2、测试
   参见http://blog.csdb.net/chenm《安装配置Hibernate+Tomcat》,除出Tomcat部分,目录结构和代码完全一致。

本文地址:http://com.8s8s.com/it/it14480.htm