Jboss 4.2 jndi data source configuration to MySql
================================================================Copy mysql-connector-java-5.1.9.jar file into jboss-4.2.0.GA\server\default\lib
jboss-4.2.0.GA\server\default\deploy\mysql-ds.xml
====================================
<datasources>
<local-tx-datasource>
<jndi-name>TestAbcDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/test_db</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>
<user-name>root</user-name>
<password>root</password>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
\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">
<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<property name="connection.datasource">java:TestAbcDS</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">false</property>
<mapping resource="com/abc/xyz/dao/Test.hbm.xml" />
</session-factory>
</hibernate-configuration>
WEB-INF\web.xml
=======================================
<resource-ref>
<res-ref-name>TestAbcDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
WEB-INF\jboss-web.xml
========================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 2.3V2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
<jboss-web>
<resource-ref>
<res-ref-name>TestAbcDS</res-ref-name>
<jndi-name>java:TestAbcDS</jndi-name>
</resource-ref>
</jboss-web>
In Java Class:
=================================
private String path = "hibernate.cfg.xml";
URL url = HibernateListener.class.getResource(path);
config = new Configuration().configure(url);
No comments:
Post a Comment