You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bob Dietrich <bo...@bobd.biz> on 2012/10/27 23:45:41 UTC
JNDI datasource error upgrading from Tomcat 7.0.23 to 7.0.27
Greetings,
I've researched this problem for several days, but I must be doing something
wrong. I'm trying to upgrade from Tomcat 7.0.23 to 7.0.27 (actually running
Liferay). I'm getting the following exception when trying to access a
datasource via Hibernate:
16:28:27,694 ERROR
[http-bio-8080-exec-1][DatasourceConnectionProvider:110] Could not find
datasource: java:/comp/env/jdbc/MySqlDS
javax.naming.NameNotFoundException: Name [java:/comp/env/jdbc/MySqlDS]
is not bound in this Context. Unable to find [java:].
at
org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at
org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at
org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceCo
nnectionProvider.java:75)
at
org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Con
nectionProviderFactory.java:143)
at
org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Con
nectionProviderFactory.java:84)
at
org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.j
ava:459)
at
org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
at
org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:286
3)
at
org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
The exact same code runs fine in 7.0.23 (I can drop the WAR file in either
instance).
Here is my $CATALINA_HOME/conf/context.xml file (comments removed):
<?xml version='1.0' encoding='utf-8'?>
<!-- The contents of this file will be loaded for each web application
-->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/MySqlDS" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
username="xxx"
password="xxx"
url="jdbc:mysql://localhost:3306/xx?useUnicode=true&characterEncoding=UT
F-8&relaxAutoCommit=true"
maxActive="200" maxIdle="30" maxWait="10000"
minIdle="3"
testWhileIdle="true" testOnBorrow="true"
timeBetweenEvictionRunsMillis="120000"
minEvictableIdleTimeMillis="600000"
validationQuery="select 1"
/>
</Context>
The web.xml from the application:
<?xml version="1.0"?>
<web-app version="2.4" 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">
<servlet>
<servlet-name>HibernateServlet</servlet-name>
<servlet-class>com.liferay.samplehibernate.servlet.HibernateServlet</servlet
-class>
</servlet>
<servlet-mapping>
<servlet-name>HibernateServlet</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
<taglib-location>
/WEB-INF/tld/liferay-portlet.tld
</taglib-location>
</taglib>
</jsp-config>
<resource-ref>
<description>data source</description>
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
And finally the the hibernate.cfg.xml file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="current_session_context_class">thread</property>
<!-- Mappings -->
<property
name="connection.datasource">java:/comp/env/jdbc/MySqlDS</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<mapping
resource="com/liferay/samplehibernate/model/FoodItem.hbm.xml" />
</session-factory>
</hibernate-configuration>
Did a bit more research. On vanilla versions of Tomcat 7.0.27 and the
corresponding Liferay bundle, I can make a global definition using the same
resource in server.xml. I can see the connection pool using psi-probe and
run queries. However, as soon as I introduce a resource-ref, either in the
app or in the global web.xml, psi-probe complains that the resource is not
configured correctly.
Any suggestions about what I'm missing? Thanks.
Bob
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: JNDI datasource error upgrading from Tomcat 7.0.23 to 7.0.27
Posted by Bob Dietrich <bo...@bobd.biz>.
@Konstantin, thanks much for your quick reply. I will try the
META-INF/context.xml resource. I'll also try running under 7.0.32, although
configuring Liferay to run can be a bit tedious and error prone (that's why
I normally use a bundle). And thanks for the closeMethod suggestion.
Bob
-----Original Message-----
From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com]
Sent: Saturday, October 27, 2012 3:28 PM
To: Tomcat Users List
Subject: Re: JNDI datasource error upgrading from Tomcat 7.0.23 to 7.0.27
2012/10/28 Bob Dietrich <bo...@bobd.biz>:
> Greetings,
> I've researched this problem for several days, but I must be doing
> something wrong. I'm trying to upgrade from Tomcat 7.0.23 to 7.0.27
> (actually running Liferay). I'm getting the following exception when
> trying to access a datasource via Hibernate:
>
> 16:28:27,694 ERROR
> [http-bio-8080-exec-1][DatasourceConnectionProvider:110] Could not
> find
> datasource: java:/comp/env/jdbc/MySqlDS
> javax.naming.NameNotFoundException: Name
> [java:/comp/env/jdbc/MySqlDS] is not bound in this Context. Unable to find
[java:].
> at
> org.apache.naming.NamingContext.lookup(NamingContext.java:820)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
> at
> org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
> at javax.naming.InitialContext.lookup(InitialContext.java:392)
> at
> org.hibernate.connection.DatasourceConnectionProvider.configure(Dataso
> urceCo
> nnectionProvider.java:75)
> at
> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvid
> er(Con
> nectionProviderFactory.java:143)
> at
> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvid
> er(Con
> nectionProviderFactory.java:84)
> at
> org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFac
> tory.j
> ava:459)
> at
> org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
> at
> org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.ja
> va:286
> 3)
> at
> org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
> at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java
> :1870)
>
> The exact same code runs fine in 7.0.23 (I can drop the WAR file in
> either instance).
>
> Here is my $CATALINA_HOME/conf/context.xml file (comments removed):
>
> <?xml version='1.0' encoding='utf-8'?>
> <!-- The contents of this file will be loaded for each web
> application
> -->
> <Context>
>
> <!-- Default set of monitored resources -->
> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>
> <Resource name="jdbc/MySqlDS" auth="Container"
> type="javax.sql.DataSource"
> driverClassName="com.mysql.jdbc.Driver"
> username="xxx"
> password="xxx"
>
> url="jdbc:mysql://localhost:3306/xx?useUnicode=true&characterEncod
> ing=UT
> F-8&relaxAutoCommit=true"
> maxActive="200" maxIdle="30" maxWait="10000"
> minIdle="3"
> testWhileIdle="true" testOnBorrow="true"
> timeBetweenEvictionRunsMillis="120000"
> minEvictableIdleTimeMillis="600000"
> validationQuery="select 1"
> />
> </Context>
>
> The web.xml from the application:
>
> <?xml version="1.0"?>
> <web-app version="2.4" 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">
> <servlet>
> <servlet-name>HibernateServlet</servlet-name>
>
> <servlet-class>com.liferay.samplehibernate.servlet.HibernateServlet</s
> ervlet
> -class>
> </servlet>
> <servlet-mapping>
> <servlet-name>HibernateServlet</servlet-name>
> <url-pattern>/servlet/*</url-pattern>
> </servlet-mapping>
> <jsp-config>
> <taglib>
>
> <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
> <taglib-location>
> /WEB-INF/tld/liferay-portlet.tld
> </taglib-location>
> </taglib>
> </jsp-config>
> <resource-ref>
> <description>data source</description>
> <res-ref-name>jdbc/MySqlDS</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> </web-app>
>
> And finally the the hibernate.cfg.xml file:
>
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-configuration PUBLIC
> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
>
> <hibernate-configuration>
> <session-factory>
> <property
> name="current_session_context_class">thread</property>
>
> <!-- Mappings -->
> <property
> name="connection.datasource">java:/comp/env/jdbc/MySqlDS</property>
> <property name="dialect">
> org.hibernate.dialect.MySQLDialect
> </property>
>
> <mapping
>
> resource="com/liferay/samplehibernate/model/FoodItem.hbm.xml" />
> </session-factory>
> </hibernate-configuration>
>
> Did a bit more research. On vanilla versions of Tomcat 7.0.27 and the
> corresponding Liferay bundle, I can make a global definition using the
> same resource in server.xml. I can see the connection pool using
> psi-probe and run queries. However, as soon as I introduce a
> resource-ref, either in the app or in the global web.xml, psi-probe
> complains that the resource is not configured correctly.
>
> Any suggestions about what I'm missing? Thanks.
>
Do you know that $CATALINA_HOME/conf/context.xml does not define a "global"
resource, but is used as the parent for webapps' own META-INF/context.xml
files?
Essentially, each web application gets its own copy of the pool.
I wonder whether "resource-ref" in web.xml is treated as a <Resource> in
app's own context.xml file and thus overwrites the default one.
1. Does it work in the current release, 7.0.32 ?
2. Does it work if you use META-INF/context.xml in your web application to
define the Resource?
3. There were many changes between 7.0.23 and 7.0.27, but none seems as a
possible cause for such change in behaviour.
BTW, I usually add closeMethod="close" attribute when configuring a database
pool.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: JNDI datasource error upgrading from Tomcat 7.0.23 to 7.0.27
Posted by Bob Dietrich <bo...@bobd.biz>.
@Aladin Thanks for your suggestion. I took a look at the thread and I'm not
clear how realms would be an issue for me (using the defaults), but that
could just be my poor understanding.
Bob
-----Original Message-----
From: Aladin Dajani [mailto:aladin.dajani@gmail.com]
Sent: Saturday, October 27, 2012 5:24 PM
To: Tomcat Users List
Subject: Re: JNDI datasource error upgrading from Tomcat 7.0.23 to 7.0.27
Hello,
I am mot familiar with Hibernate or Liferay, but I ran into what appear to
be similar. Look onto the thread titled "
JDBCRealm conection timeout failure on getPassword" in thus list. It may
help.
Aladin
On Oct 27, 2012, at 6:28 PM, Konstantin Kolinko <kn...@gmail.com>
wrote:
> 2012/10/28 Bob Dietrich <bo...@bobd.biz>:
>> Greetings,
>> I've researched this problem for several days, but I must be doing
>> something wrong. I'm trying to upgrade from Tomcat 7.0.23 to 7.0.27
>> (actually running Liferay). I'm getting the following exception when
>> trying to access a datasource via Hibernate:
>>
>> 16:28:27,694 ERROR
>> [http-bio-8080-exec-1][DatasourceConnectionProvider:110] Could not
>> find
>> datasource: java:/comp/env/jdbc/MySqlDS
>> javax.naming.NameNotFoundException: Name
>> [java:/comp/env/jdbc/MySqlDS] is not bound in this Context. Unable to
find [java:].
>> at
>> org.apache.naming.NamingContext.lookup(NamingContext.java:820)
>> at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
>> at
>> org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
>> at javax.naming.InitialContext.lookup(InitialContext.java:392)
>> at
>> org.hibernate.connection.DatasourceConnectionProvider.configure(Datas
>> ourceCo
>> nnectionProvider.java:75)
>> at
>> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvi
>> der(Con
>> nectionProviderFactory.java:143)
>> at
>> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvi
>> der(Con
>> nectionProviderFactory.java:84)
>> at
>> org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFa
>> ctory.j
>> ava:459)
>> at
>> org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
>> at
>> org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.j
>> ava:286
>> 3)
>> at
>> org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
>> at
>> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
>> a:1870)
>>
>> The exact same code runs fine in 7.0.23 (I can drop the WAR file in
>> either instance).
>>
>> Here is my $CATALINA_HOME/conf/context.xml file (comments removed):
>>
>> <?xml version='1.0' encoding='utf-8'?>
>> <!-- The contents of this file will be loaded for each web
>> application
>> -->
>> <Context>
>>
>> <!-- Default set of monitored resources -->
>> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>>
>> <Resource name="jdbc/MySqlDS" auth="Container"
>> type="javax.sql.DataSource"
>> driverClassName="com.mysql.jdbc.Driver"
>> username="xxx"
>> password="xxx"
>>
>> url="jdbc:mysql://localhost:3306/xx?useUnicode=true&characterEnco
>> ding=UT
>> F-8&relaxAutoCommit=true"
>> maxActive="200" maxIdle="30" maxWait="10000"
>> minIdle="3"
>> testWhileIdle="true" testOnBorrow="true"
>> timeBetweenEvictionRunsMillis="120000"
>> minEvictableIdleTimeMillis="600000"
>> validationQuery="select 1"
>> />
>> </Context>
>>
>> The web.xml from the application:
>>
>> <?xml version="1.0"?>
>> <web-app version="2.4" 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">
>> <servlet>
>> <servlet-name>HibernateServlet</servlet-name>
>>
>> <servlet-class>com.liferay.samplehibernate.servlet.HibernateServlet</
>> servlet
>> -class>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>HibernateServlet</servlet-name>
>> <url-pattern>/servlet/*</url-pattern>
>> </servlet-mapping>
>> <jsp-config>
>> <taglib>
>>
>> <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
>> <taglib-location>
>> /WEB-INF/tld/liferay-portlet.tld
>> </taglib-location>
>> </taglib>
>> </jsp-config>
>> <resource-ref>
>> <description>data source</description>
>> <res-ref-name>jdbc/MySqlDS</res-ref-name>
>> <res-type>javax.sql.DataSource</res-type>
>> <res-auth>Container</res-auth>
>> </resource-ref>
>> </web-app>
>>
>> And finally the the hibernate.cfg.xml file:
>>
>> <?xml version="1.0"?>
>> <!DOCTYPE hibernate-configuration PUBLIC
>> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
>>
>> <hibernate-configuration>
>> <session-factory>
>> <property
>> name="current_session_context_class">thread</property>
>>
>> <!-- Mappings -->
>> <property
>> name="connection.datasource">java:/comp/env/jdbc/MySqlDS</property>
>> <property name="dialect">
>> org.hibernate.dialect.MySQLDialect
>> </property>
>>
>> <mapping
>>
>> resource="com/liferay/samplehibernate/model/FoodItem.hbm.xml" />
>> </session-factory>
>> </hibernate-configuration>
>>
>> Did a bit more research. On vanilla versions of Tomcat 7.0.27 and the
>> corresponding Liferay bundle, I can make a global definition using
>> the same resource in server.xml. I can see the connection pool using
>> psi-probe and run queries. However, as soon as I introduce a
>> resource-ref, either in the app or in the global web.xml, psi-probe
>> complains that the resource is not configured correctly.
>>
>> Any suggestions about what I'm missing? Thanks.
>
> Do you know that $CATALINA_HOME/conf/context.xml does not define a
> "global" resource, but is used as the parent for webapps' own
> META-INF/context.xml files?
>
> Essentially, each web application gets its own copy of the pool.
>
> I wonder whether "resource-ref" in web.xml is treated as a <Resource>
> in app's own context.xml file and thus overwrites the default one.
>
> 1. Does it work in the current release, 7.0.32 ?
> 2. Does it work if you use META-INF/context.xml in your web
> application to define the Resource?
> 3. There were many changes between 7.0.23 and 7.0.27, but none seems
> as a possible cause for such change in behaviour.
>
> BTW, I usually add closeMethod="close" attribute when configuring a
> database pool.
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: JNDI datasource error upgrading from Tomcat 7.0.23 to 7.0.27
Posted by Aladin Dajani <al...@gmail.com>.
Hello,
I am mot familiar with Hibernate or Liferay, but I ran into what
appear to be similar. Look onto the thread titled "
JDBCRealm conection timeout failure on getPassword" in thus list. It may help.
Aladin
On Oct 27, 2012, at 6:28 PM, Konstantin Kolinko <kn...@gmail.com> wrote:
> 2012/10/28 Bob Dietrich <bo...@bobd.biz>:
>> Greetings,
>> I've researched this problem for several days, but I must be doing something
>> wrong. I'm trying to upgrade from Tomcat 7.0.23 to 7.0.27 (actually running
>> Liferay). I'm getting the following exception when trying to access a
>> datasource via Hibernate:
>>
>> 16:28:27,694 ERROR
>> [http-bio-8080-exec-1][DatasourceConnectionProvider:110] Could not find
>> datasource: java:/comp/env/jdbc/MySqlDS
>> javax.naming.NameNotFoundException: Name [java:/comp/env/jdbc/MySqlDS]
>> is not bound in this Context. Unable to find [java:].
>> at
>> org.apache.naming.NamingContext.lookup(NamingContext.java:820)
>> at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
>> at
>> org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
>> at javax.naming.InitialContext.lookup(InitialContext.java:392)
>> at
>> org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceCo
>> nnectionProvider.java:75)
>> at
>> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Con
>> nectionProviderFactory.java:143)
>> at
>> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Con
>> nectionProviderFactory.java:84)
>> at
>> org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.j
>> ava:459)
>> at
>> org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
>> at
>> org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:286
>> 3)
>> at
>> org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
>> at
>> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
>>
>> The exact same code runs fine in 7.0.23 (I can drop the WAR file in either
>> instance).
>>
>> Here is my $CATALINA_HOME/conf/context.xml file (comments removed):
>>
>> <?xml version='1.0' encoding='utf-8'?>
>> <!-- The contents of this file will be loaded for each web application
>> -->
>> <Context>
>>
>> <!-- Default set of monitored resources -->
>> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>>
>> <Resource name="jdbc/MySqlDS" auth="Container"
>> type="javax.sql.DataSource"
>> driverClassName="com.mysql.jdbc.Driver"
>> username="xxx"
>> password="xxx"
>>
>> url="jdbc:mysql://localhost:3306/xx?useUnicode=true&characterEncoding=UT
>> F-8&relaxAutoCommit=true"
>> maxActive="200" maxIdle="30" maxWait="10000"
>> minIdle="3"
>> testWhileIdle="true" testOnBorrow="true"
>> timeBetweenEvictionRunsMillis="120000"
>> minEvictableIdleTimeMillis="600000"
>> validationQuery="select 1"
>> />
>> </Context>
>>
>> The web.xml from the application:
>>
>> <?xml version="1.0"?>
>> <web-app version="2.4" 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">
>> <servlet>
>> <servlet-name>HibernateServlet</servlet-name>
>>
>> <servlet-class>com.liferay.samplehibernate.servlet.HibernateServlet</servlet
>> -class>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>HibernateServlet</servlet-name>
>> <url-pattern>/servlet/*</url-pattern>
>> </servlet-mapping>
>> <jsp-config>
>> <taglib>
>>
>> <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
>> <taglib-location>
>> /WEB-INF/tld/liferay-portlet.tld
>> </taglib-location>
>> </taglib>
>> </jsp-config>
>> <resource-ref>
>> <description>data source</description>
>> <res-ref-name>jdbc/MySqlDS</res-ref-name>
>> <res-type>javax.sql.DataSource</res-type>
>> <res-auth>Container</res-auth>
>> </resource-ref>
>> </web-app>
>>
>> And finally the the hibernate.cfg.xml file:
>>
>> <?xml version="1.0"?>
>> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
>> Configuration DTD 3.0//EN"
>> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
>>
>> <hibernate-configuration>
>> <session-factory>
>> <property
>> name="current_session_context_class">thread</property>
>>
>> <!-- Mappings -->
>> <property
>> name="connection.datasource">java:/comp/env/jdbc/MySqlDS</property>
>> <property name="dialect">
>> org.hibernate.dialect.MySQLDialect
>> </property>
>>
>> <mapping
>>
>> resource="com/liferay/samplehibernate/model/FoodItem.hbm.xml" />
>> </session-factory>
>> </hibernate-configuration>
>>
>> Did a bit more research. On vanilla versions of Tomcat 7.0.27 and the
>> corresponding Liferay bundle, I can make a global definition using the same
>> resource in server.xml. I can see the connection pool using psi-probe and
>> run queries. However, as soon as I introduce a resource-ref, either in the
>> app or in the global web.xml, psi-probe complains that the resource is not
>> configured correctly.
>>
>> Any suggestions about what I'm missing? Thanks.
>
> Do you know that $CATALINA_HOME/conf/context.xml does not define a
> "global" resource, but is used as the parent for webapps' own
> META-INF/context.xml files?
>
> Essentially, each web application gets its own copy of the pool.
>
> I wonder whether "resource-ref" in web.xml is treated as a <Resource>
> in app's own context.xml file and thus overwrites the default one.
>
> 1. Does it work in the current release, 7.0.32 ?
> 2. Does it work if you use META-INF/context.xml in your web
> application to define the Resource?
> 3. There were many changes between 7.0.23 and 7.0.27, but none seems
> as a possible cause for such change in behaviour.
>
> BTW, I usually add closeMethod="close" attribute when configuring a
> database pool.
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: JNDI datasource error upgrading from Tomcat 7.0.23 to 7.0.27
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/10/28 Bob Dietrich <bo...@bobd.biz>:
> Greetings,
> I've researched this problem for several days, but I must be doing something
> wrong. I'm trying to upgrade from Tomcat 7.0.23 to 7.0.27 (actually running
> Liferay). I'm getting the following exception when trying to access a
> datasource via Hibernate:
>
> 16:28:27,694 ERROR
> [http-bio-8080-exec-1][DatasourceConnectionProvider:110] Could not find
> datasource: java:/comp/env/jdbc/MySqlDS
> javax.naming.NameNotFoundException: Name [java:/comp/env/jdbc/MySqlDS]
> is not bound in this Context. Unable to find [java:].
> at
> org.apache.naming.NamingContext.lookup(NamingContext.java:820)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
> at
> org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
> at javax.naming.InitialContext.lookup(InitialContext.java:392)
> at
> org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceCo
> nnectionProvider.java:75)
> at
> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Con
> nectionProviderFactory.java:143)
> at
> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Con
> nectionProviderFactory.java:84)
> at
> org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.j
> ava:459)
> at
> org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
> at
> org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:286
> 3)
> at
> org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
> at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
>
> The exact same code runs fine in 7.0.23 (I can drop the WAR file in either
> instance).
>
> Here is my $CATALINA_HOME/conf/context.xml file (comments removed):
>
> <?xml version='1.0' encoding='utf-8'?>
> <!-- The contents of this file will be loaded for each web application
> -->
> <Context>
>
> <!-- Default set of monitored resources -->
> <WatchedResource>WEB-INF/web.xml</WatchedResource>
>
> <Resource name="jdbc/MySqlDS" auth="Container"
> type="javax.sql.DataSource"
> driverClassName="com.mysql.jdbc.Driver"
> username="xxx"
> password="xxx"
>
> url="jdbc:mysql://localhost:3306/xx?useUnicode=true&characterEncoding=UT
> F-8&relaxAutoCommit=true"
> maxActive="200" maxIdle="30" maxWait="10000"
> minIdle="3"
> testWhileIdle="true" testOnBorrow="true"
> timeBetweenEvictionRunsMillis="120000"
> minEvictableIdleTimeMillis="600000"
> validationQuery="select 1"
> />
> </Context>
>
> The web.xml from the application:
>
> <?xml version="1.0"?>
> <web-app version="2.4" 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">
> <servlet>
> <servlet-name>HibernateServlet</servlet-name>
>
> <servlet-class>com.liferay.samplehibernate.servlet.HibernateServlet</servlet
> -class>
> </servlet>
> <servlet-mapping>
> <servlet-name>HibernateServlet</servlet-name>
> <url-pattern>/servlet/*</url-pattern>
> </servlet-mapping>
> <jsp-config>
> <taglib>
>
> <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
> <taglib-location>
> /WEB-INF/tld/liferay-portlet.tld
> </taglib-location>
> </taglib>
> </jsp-config>
> <resource-ref>
> <description>data source</description>
> <res-ref-name>jdbc/MySqlDS</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> </web-app>
>
> And finally the the hibernate.cfg.xml file:
>
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
> Configuration DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
>
> <hibernate-configuration>
> <session-factory>
> <property
> name="current_session_context_class">thread</property>
>
> <!-- Mappings -->
> <property
> name="connection.datasource">java:/comp/env/jdbc/MySqlDS</property>
> <property name="dialect">
> org.hibernate.dialect.MySQLDialect
> </property>
>
> <mapping
>
> resource="com/liferay/samplehibernate/model/FoodItem.hbm.xml" />
> </session-factory>
> </hibernate-configuration>
>
> Did a bit more research. On vanilla versions of Tomcat 7.0.27 and the
> corresponding Liferay bundle, I can make a global definition using the same
> resource in server.xml. I can see the connection pool using psi-probe and
> run queries. However, as soon as I introduce a resource-ref, either in the
> app or in the global web.xml, psi-probe complains that the resource is not
> configured correctly.
>
> Any suggestions about what I'm missing? Thanks.
>
Do you know that $CATALINA_HOME/conf/context.xml does not define a
"global" resource, but is used as the parent for webapps' own
META-INF/context.xml files?
Essentially, each web application gets its own copy of the pool.
I wonder whether "resource-ref" in web.xml is treated as a <Resource>
in app's own context.xml file and thus overwrites the default one.
1. Does it work in the current release, 7.0.32 ?
2. Does it work if you use META-INF/context.xml in your web
application to define the Resource?
3. There were many changes between 7.0.23 and 7.0.27, but none seems
as a possible cause for such change in behaviour.
BTW, I usually add closeMethod="close" attribute when configuring a
database pool.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org