2

For some reasons I've to fine-tune the jdbc connecton, and I've found, the context.xml is the way I can do that. ( http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html#PostgreSQL )

So, I create context.xml:

<Context>
<Resource
    name="jdbc/connectorDs"
    auth="Container"
    type="javax.sql.DataSource"
    driverClassName="org.postgresql.Driver"
    url="jdbc:postgresql://localhost/somedb"
    username="pguser"
    password="pgpw"
    maxActive="20"
    maxIdle="10"
    maxWait="-1" />
</Context>

Add some config to web.xml:

<resource-ref>
    <description>postgreSQL Datasource example</description>
    <res-ref-name>jdbc/connectorDs</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

And modify the hibernate.cfg.xml:

<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.datasource">java:jdbc/connectorDs</property>

<!-- THE ORIGINAL CONFIG -->
<!-- <property name="connection.url">jdbc:postgresql://localhost/somedb</property> -->
<!-- <property name="connection.username">pguser</property> -->
<!-- <property name="connection.password">pgpw</property> -->

But this kind of konfig doesn't work: SEVERE: Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasource. I suppose the dataource not exist or the datasource connection string java:jdbc/connectorDs is not proper. Anybody has any experience with it? How to set my connection propertly, or how to set additional properties on connection?

Thanks in advance.

2 Answers 2

2

try

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

I don't think you need to declare datasource in both web.xml and server.xml. Try to remove the web.xml one if it still don't run

Sign up to request clarification or add additional context in comments.

1 Comment

Works fine without web.xml config code. Thanks both of you.
2

In hibernate.cfg.xml, try replacing

<property name="hibernate.connection.datasource">java:jdbc/connectorDs</property>

with

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.