Hi,
If I build my war file and deploy it to JBoss using the following config file :
Code:
<?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">
<!-- How to use this ?
<property name="hibernate.jndi.class">org.jnp.interfaces.NamingContextFactory</property>
<property name="hibernate.jndi.url">jnp://localhost:1099/</property>
-->
<!-- JNDI configuration for Sybase
-->
<property name="hibernate.connection.datasource">java:SybaseDS</property>
<property name="hibernate.dialect">org.hibernate.dialect.SybaseDialect</property>
<!-- Plugin ConnectionProvider -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<mapping resource="blahblahblah.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I don't have any problem at all. The web app running correctly under JBoss.
My problem is, I have a test case, in which I would like to run using JUnit.
The following JUnit task does not work :
Code:
<!-- Need to put junit.jar into $ANT_HOME/lib !!! -->
<target name="junit" depends="clean ,prepare ,compile" description="Run the test suite">
<mkdir dir="${test.out.dir}"/>
<junit dir="${webinf.dir}/classes" printsummary="yes" jvm="java" fork="true" haltonfailure="yes" showoutput="true">
<classpath refid="compile.classpath"/>
<formatter type="plain"/>
<formatter type="xml"/>
<test name="example.test.AllTests" todir="${test.out.dir}" haltonfailure="no"/>
</junit>
</target>
because if I invoke Ant, I got this error :
[junit] 13:54:14,548 FATAL DatasourceConnectionProvider: Could not find datasource: java:SybaseDS
[junit] javax.naming.NoInitialContextException: Need to specify class name in environment or system property,
or as an applet parameter, or in an application resource file: java.naming.factory.initial
[junit] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
[junit] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
[junit] at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
[junit] at javax.naming.InitialContext.lookup(InitialContext.java:351)
[junit] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
[junit] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
If I specify the JNDI Class&URL, so it becomes :
Code:
...
<!-- How to use this ?
-->
<property name="hibernate.jndi.class">org.jnp.interfaces.NamingContextFactory</property>
<property name="hibernate.jndi.url">jnp://localhost:1099/</property>
...
I got different error :
[junit] 13:59:28,081 FATAL DatasourceConnectionProvider: Could not find datasource: java:SybaseDS
[junit] javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
[junit] at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1302)
[junit] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1382)
[junit] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
[junit] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
[junit] at javax.naming.InitialContext.lookup(InitialContext.java:351)
[junit] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
Anybody knows how to configure my hibernate.cfg.xml so I can run my test case ?
Thanks for any help/suggestions/pointers.
Thanks,
nusa.