persistence@glassfish.java.net

Re: non-jta-data-source doesn't work with Tomcat 5.5?

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 26 Feb 2007 12:53:24 -0800

Hi Jon,

Just a guess... Does your test code work if you use "jdbc/Reservations"? If not,
may be you need to escape ":" in the url?

thanks,
-marina

Jon Miller wrote:
> Hi Marina,
>
> I'm using the following settings. For the string in the
> non-jta-data-source element, I've tried
> "java:comp/env/jdbc/Reservations", "comp/env/jdbc/Reservations",
> "env/jdbc/Reservations", and "jdbc/Reservations". I'm able to use the
> following code in my app to verify that the data source is configured
> properly in the web app.
>
> try {
> javax.sql.DataSource ds = (javax.sql.DataSource)
> new javax.naming.InitialContext().lookup(
> "java:comp/env/jdbc/Reservations");
> logger.info("OBTAINED CONNECTION!");
> }
> catch(javax.naming.NamingException e) {
> logger.info(e.toString());
> }
>
> I receive this exception if I try "java:comp/env/jdbc/Reservations".
>
> Exception [TOPLINK-7060] (Oracle TopLink Essentials - 9.1 (Build
> b36-rc)): oracle.toplink.essentials.exceptions.ValidationException
> Exception Description: Cannot acquire data source
> [java:comp/env/jdbc/Reservations].
> Internal Exception: javax.naming.NamingException: This context must be
> accessed throught a java: URL
> javax.xml.ws.soap.SOAPFaultException: Exception [TOPLINK-7060] (Oracle
> TopLink Essentials - 9.1 (Build b36-rc)):
> oracle.toplink.essentials.exceptions.ValidationException
> Exception Description: Cannot acquire data source
> [java:comp/env/jdbc/Reservations].
> Internal Exception: javax.naming.NamingException: This context must be
> accessed throught a java: URL
> at
> com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:163)
> at
> com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:102)
>
> at
> com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:236)
>
> at
> com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:206)
>
> at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
> at $Proxy26.saveUser(Unknown Source)
> at
> edu.uchicago.at.reservations.ReservationsWebServiceTest.testSaveGetAndRemoveUser(ReservationsWebServiceTest.java:529)
>
> Caused by: javax.persistence.PersistenceException: Exception
> [TOPLINK-7060] (Oracle TopLink Essentials - 9.1 (Build b36-rc)):
> oracle.toplink.essentials.exceptions.ValidationException
> Exception Description: Cannot acquire data source
> [java:comp/env/jdbc/Reservations].
> Internal Exception: javax.naming.NamingException: This context must be
> accessed throught a java: URL
> at
> oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:220)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:78)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:111)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:105)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:76)
>
> at
> edu.uchicago.at.reservations.ReservationsService.saveUser(ReservationsService.java:725)
>
>
> And this exception if I try "jdbc/Reservations" (similar if I try
> "comp/env/jdbc/Reservations", or "env/jdbc/Reservations").
>
> Exception [TOPLINK-7060] (Oracle TopLink Essentials - 9.1 (Build
> b36-rc)): oracle.toplink.essentials.exceptions.ValidationException
> Exception Description: Cannot acquire data source [jdbc/Reservations].
> Internal Exception: javax.naming.NameNotFoundException: Name jdbc is not
> bound in this Context
> javax.xml.ws.soap.SOAPFaultException: Exception [TOPLINK-7060] (Oracle
> TopLink Essentials - 9.1 (Build b36-rc)):
> oracle.toplink.essentials.exceptions.ValidationException
> Exception Description: Cannot acquire data source [jdbc/Reservations].
> Internal Exception: javax.naming.NameNotFoundException: Name jdbc is not
> bound in this Context
> at
> com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:163)
> at
> com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:102)
>
> at
> com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:236)
>
> at
> com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:206)
>
> at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
> at $Proxy26.saveUser(Unknown Source)
> at
> edu.uchicago.at.reservations.ReservationsWebServiceTest.testSaveGetAndRemoveUser(ReservationsWebServiceTest.java:529)
>
> Caused by: javax.persistence.PersistenceException: Exception
> [TOPLINK-7060] (Oracle TopLink Essentials - 9.1 (Build b36-rc)):
> oracle.toplink.essentials.exceptions.ValidationException
> Exception Description: Cannot acquire data source [jdbc/Reservations].
> Internal Exception: javax.naming.NameNotFoundException: Name jdbc is not
> bound in this Context
> at
> oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:220)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:78)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:111)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:105)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:76)
>
> at
> edu.uchicago.at.reservations.ReservationsService.saveUser(ReservationsService.java:725)
>
>
> <!-- context.xml -->
>
> <Resource name="jdbc/Reservations" auth="Container"
> type="javax.sql.DataSource"
> driverClassName="com.mysql.jdbc.Driver"
>
> url="jdbc:mysql://localhost:3306/Reservations?autoReconnectForPools=true"
> username="Reservations" password="" maxActive="5"
> maxIdle="5" maxWait="10000" removeAbandoned="true"
> removeAbandonedTimeout="60" logAbandoned="true"/>
>
> <!-- web.xml -->
>
> <resource-ref>
> <res-ref-name>jdbc/Reservations</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
> <!-- persistence.xml -->
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
> <persistence-unit name="Reservations2"
> transaction-type="RESOURCE_LOCAL">
>
> <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
>
> <non-jta-data-source>jdbc/Reservations</non-jta-data-source>
> <class>edu.uchicago.at.common.persistence.entity.AuditObject</class>
> <class>edu.uchicago.at.common.persistence.entity.Person</class>
> <class>edu.uchicago.at.common.persistence.entity.Role</class>
> <class>edu.uchicago.at.common.persistence.entity.User</class>
> <class>edu.uchicago.at.reservations.persistence.entity.Item</class>
>
> <class>edu.uchicago.at.reservations.persistence.entity.Reservation</class>
> <properties>
> <property name="toplink.logging.logger" value="JavaLogger"/>
> <property name="toplink.logging.level" value="FINE"/>
> <property name="toplink.cache.shared.default" value="false"/>
> </properties>
> </persistence-unit>
> </persistence>
>
> In reality, although I think it's important that this work, in this case
> I'd rather use the built-in connection pool. The problem with that is
> that I want it to automatically handle broken connections. i.e. say
> there's a connection in the pool that is established, then the database
> server goes down, then it comes back up, then a client attempts to do a
> query, currently, it throws an exception. It does this for every
> connection in the pool. What I want it to do is handle this gracefully.
> i.e. if the connection is broken, establish a new connection and remove
> the old connection from the pool. This should all happen at once and no
> exception should get down into the application code. I'm pretty sure the
> Tomcat connection pool works this way.
>
> Jon
>
> ----- Original Message ----- From: "Marina Vatkina"
> <Marina.Vatkina_at_Sun.COM>
> To: <persistence_at_glassfish.dev.java.net>
> Sent: Friday, February 23, 2007 9:05 PM
> Subject: Re: non-jta-data-source doesn't work with Tomcat 5.5?
>
>
>> Jon,
>>
>> Can you post your persistence.xml file?
>>
>> thanks,
>> -marina
>>
>> Jon Miller wrote:
>>
>>> No one knows the answer to this? I'm not looking forward to having to
>>> restart my app everytime the database goes down, so, I'm hoping to
>>> get GP working with Tomcat's connection pool which I've used with
>>> Hibernate in the past without problem. While it may be the case that
>>> Tomcat's JNDI implementation isn't what it should be, I believe it's
>>> important that GP work with it because a lot of users will probably
>>> try to use it that way. I wasn't able to get it to work using the
>>> latest build of GP. This IMHO isn't something you shouldn't have to
>>> use a customizer to get working.
>>>
>>> Jon
>>>
>>> ----- Original Message ----- From: "Jon Miller" <jemiller_at_uchicago.edu>
>>> To: "Glassfish Persistence List" <persistence_at_glassfish.dev.java.net>
>>> Sent: Tuesday, February 20, 2007 4:53 PM
>>> Subject: non-jta-data-source doesn't work with Tomcat 5.5?
>>>
>>>
>>>> Hi all,
>>>>
>>>> I'm using GP V2 B36 with Java 1.5.0_09 and Tomcat 5.5.17. I've been
>>>> having problems with Glassfish Persistences built-in connection pool
>>>> not handling broken connections correctly. Specifically, it seems to
>>>> have problems dealing with the fact that MySQL times out connections
>>>> after 8 hours. So, I decided to try to use the non-jta-data-source
>>>> setting instead and use Tomcat's connection pool. However, I can't
>>>> seem to get it to work. I found the following article which
>>>> indicates it doesn't work unless you use a customizer. Can anyone
>>>> confirm whether this is the case?
>>>>
>>>> http://forums.java.net/jive/thread.jspa?messageID=189962
>>>>
>>>> Jon
>>>>
>>