Hi;

This is really a hibernate issue but as some people on this list may hit
this problem due to the hibernate docs, I figured I should post here too.

Tomcat 5.5 has changed how it does the JNDI settings for a JDBC setup. I am
still working through some minor details making sure I have them exactly
right. But the following works.

First, do not place anything in server.xml. Everything you do will go in
your webapp directory. My webapp is named store.

Note: I do not create a war when developing so this is in an exploded
directory.

META-INF/context.xml(complete):
<Context path="/store" docBase="store"
        debug="5" reloadable="true" crossContext="true">
  <Resource name="jdbc/storeDB" auth="Container" type="javax.sql.DataSource"
   username="sa" password="mmouse"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
 
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=StoreTest;Select
Method=cursor"
   maxActive="8" maxIdle="4"/>
</Context>

web.xml (just the resource part):
<web-app xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
version="2.4">

...

<resource-ref>
   <description>Connection to my DB.</description>
   <res-ref-name>jdbc/storeDB</res-ref-name>
   <res-type>javax.sql.DataSource </res-type>
   <res-auth>Container</res-auth>
</resource-ref>

...

</web-app>

hibernate.cfg.xml (just DB part):
    <session-factory>
  <property name="show_sql">false</property>
  <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

  <property
name="connection.datasource">java:/comp/env/jdbc/storeDB</property>

  ...

    </session-factory>

</hibernate-configuration>

AND - this is important - this will not work when run from IntelliJ! It only
works if you start Tomcat and use it normally. 

Running under IntelliJ

Ok, here's the IntelliJ part you have to do. Lets assume your webapp is
named store.

1) copy webapps/store/META-INF/context.xml to %Tomcat
5.5%\conf\Catalina\localhost/store.xml - note the filename change.

2) In the run/debug configuration, deployment tab, set the application
context to /store (the default is /).

3) In the server tab the startup page is now
http://localhost:8080/store/index.html (the store directory is added).

And then - - it works!!!

thanks - dave

 

Reply via email to