Following the "Using Hibernate with JBoss" on
http://www.hibernate.org/66.html ,
I created a sar package and deployed it to JBoss 4.0.0's default/deploy folder. The JBoss 4.0.0 is embedded with Hibernate 2.1.5.
The sar package includes the following files:
/com/xx/hibernate/po/Teacher.class
/com/xx/hibernate/po/Student.class
/com/xx/hibernate/po/Book.class
/com/xx/hibernate/po/Teacher.hbm.xml
/com/xx/hibernate/po/Student.hbm.xml
/com/xx/hibernate/po/Book.hbm.xml
/hibernate.cfm.xml
and the file related to JBoss
/META-INF/jboss-service.xml
the /hibernate.cfm.xml looks like:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- Generated file - Do not edit! -->
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- properties -->
<property name="connection.datasource">java:/myHibernateSqlServerDB</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<!-- mapping files -->
<mapping resource="com/xx/hibernate/po/Book.hbm.xml"/>
<mapping resource="com/xx/hibernate/po/Student.hbm.xml"/>
<mapping resource="com/xx/hibernate/po/Teacher.hbm.xml"/>
</session-factory>
</hibernate-configuration>
the jboss-service.xml looks like:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<!-- Generated file - Do not edit! -->
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=myHibernate">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=myHibernateSqlServerDB</depends>
<attribute name="MapResources">com/xx/hibernate/po/Book.hbm.xml,com/xx/hibernate/po/Student.hbm.xml,com/xx/hibernate/po/Teacher.hbm.xml</attribute>
<attribute name="JndiName">java:/HibernateFactory</attribute>
<attribute name="Datasource">java:/myHibernateSqlServerDB</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.SQLServerDialect</attribute>
<attribute name="UseOuterJoin">true</attribute>
<attribute name="ShowSql">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
</mbean>
</server>
and the mssql-ds.xml looks like:
Code:
<datasources>
<local-tx-datasource>
<jndi-name>myHibernateSqlServerDB</jndi-name>
<connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=hibernate;SelectMethod=cursor</connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password></password>
<metadata>
<type-mapping>MS SQLSERVER2000</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
When firing up the JBoss, I got a error message:
15:46:42,070 FATAL [DatasourceConnectionProvider] Could not find datasource: java:/myHibernateSqlServerDB
javax.naming.NameNotFoundException: myHibernateSqlServerDB not bound
And if I removed the sar package from JBoss 4.0.0 's defaul/deploy folder, the Datasource just worked well.
Someone suggested to remove this line of the jboss-service.xml, however, I got the same error message.
Code:
<depends>jboss.jca:service=LocalTxCM,name=myHibernateSqlServerDB</depends>
So, why did the error happen when deploying my sar package???