AbstractMethodError caused by setCharacterStream - java

I am deploying a war that is working on my own machine and getting an error:
java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V
Full Stack Trace:
14:35:18.734 [scheduler-1] ERROR o.s.s.s.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V
at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$4$1.doBind(ClobTypeDescriptor.java:131) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:90) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:286) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:281) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:56) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2857) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3121) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:349) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1222) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77) ~[hibernate-entitymanager-4.3.6.Final.jar:4.3.6.Final]
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:515) ~[spring-orm-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at com.sun.proxy.$Proxy73.apply(Unknown Source) ~[na:na]
at ec.europa.eu.egrants.emailmonitoring.services.chains.forms.ApplicationFormChain.apply(ApplicationFormChain.java:37) ~[email-monitoring-1.0-SNAPSHOT.jar:na]
at ec.europa.eu.egrants.emailmonitoring.services.chains.forms.ApplicationFormChain.apply(ApplicationFormChain.java:19) ~[email-monitoring-1.0-SNAPSHOT.jar:na]
at ec.europa.eu.egrants.emailmonitoring.ChainService.forEach(ChainService.java:50) ~[email-monitoring-1.0-SNAPSHOT.jar:na]
at ec.europa.eu.egrants.emailmonitoring.ChainService.execute(ChainService.java:62) ~[email-monitoring-1.0-SNAPSHOT.jar:na]
at ec.europa.eu.egrants.emailmonitoring.services.email.EmailLocalFolderMonitor.execute(EmailLocalFolderMonitor.java:81) ~[email-monitoring-1.0-SNAPSHOT.jar:na]
at ec.europa.eu.egrants.emailmonitoring.services.email.EmailScheduler.pollEmails(EmailScheduler.java:27) ~[email-monitoring-1.0-SNAPSHOT.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_71]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_71]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_71]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) [na:1.7.0_71]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [na:1.7.0_71]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_71]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_71]
Update
1 ) Reading on the internet I a message post # https://developer.jboss.org/thread/213711?tstart=0&_sscc=t :
use Hibernate with c3p0.
I had exactly the same problem after an attempt to upgrade from
Hibernate 4.1.3 to 4.1.8.
Downgrading back to 4.1.3 solved the problem.
c3p0 version in both cases is the same: 0.9.1.
2) The answer at Abstract Method Error states that is could be "due to version incompatibility in some of the jar file."
3) Same error: Error when saving #Lob with hibernate java mysql
Update2
I was able to bypass the error ( fix? ) by changing the Resource driverClass in server.xml.
I had the following:
<Resource auth="Container"
driverClass="oracle.jdbc.OracleDriver"
maxPoolSize="20"
minPoolSize="2"
acquireIncrement="1"
name="jdbc/g"
user="egrants"
password="egrants"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:oracle:thin:#//localhost:1521/XE"
automaticTestTable="t_test_c3p0" idleConnectionTestPeriod="300"/>
Changing to the following stopped the error:
<Resource
name="jdbc/g"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#127.0.0.1:1521:xe"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="root"
password="root"
maxActive="20"
validationQuery="SELECT 1 FROM DUAL;"
testOnBorrow="true"
maxIdle="10"
maxWait="-1"/>
I have a feeling though there must be a downsite to this switch since the previous developer had written the previous definition.
How would I go about using the original c3p0 definition but avoiding the error?
Next things to try:
Change a jar file on the tomcat server?
Modifying my pom.xml .

Summary
Two workarounds/fixes I found:
Updating the JAR files within the tomcat/lib folder
Switching to a different driver in my server.xml resource definition.
Updating Jar files
Adding a definition in my pom.xml didn't work strangely as they didn't seem to be generated in the war. I resorted to updating the jars in the tomcat/lib folder.
cd apache-tomcat-6_0_36-ep-01/lib
ls
mv c3p0-0.9.2-pre4.jar c3p0-0.9.2-pre4.jar.OLD
wget http://central.maven.org/maven2/com/mchange/c3p0/0.9.5/c3p0-0.9.5.jar
mv mchange-commons-java-0.2.2.jar mchange-commons-java-0.2.2.jar.OLD
wget http://central.maven.org/maven2/com/mchange/mchange-commons-java/0.2.9/mchange-commons-java-0.2.9.jar
Switching to Different Driver
I was able to bypass the error ( fix? ) by changing the Resource driverClass in server.xml.
I had the following:
<Resource auth="Container"
driverClass="oracle.jdbc.OracleDriver"
maxPoolSize="20"
minPoolSize="2"
acquireIncrement="1"
name="jdbc/g"
user="root"
password="root"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:oracle:thin:#//localhost:1521/XE"
automaticTestTable="t_test_c3p0" idleConnectionTestPeriod="300"/>
Changing to the following stopped the error:
<Resource
name="jdbc/g"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#127.0.0.1:1521:xe"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="root"
password="root"
maxActive="20"
validationQuery="SELECT 1 FROM DUAL;"
testOnBorrow="true"
maxIdle="10"
maxWait="-1"/>
I have a feeling though there must be a downsite to this switch since the previous developer had written the previous definition.

Related

Add H2 database to Jetty with OSGI - cannot resolve driver

I am using standalone Jetty for my webapp with the org.eclipse.jetty.osgi.boot bundle.
So far, everything worked out quite satisfying. But now I tried to use authentication and add a JDBS datasource in order to store my usercredentials.
To do so, I added the following code to my jetty.xml (according to the jetty documentation):
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/admin</Arg>
<Arg>
<New class="org.h2.jdbcx.JdbcDataSource">
<Set name="URL">jdbc:h2:C:\Users\Stephan\frontonics_data\admin</Set>
<Set name="user">sa</Set>
<Set name="password"></Set>
</New>
</Arg>
</New>
I also created a properties file with the name of the driver (org.h2.Driver), the URL to the database, and so on.
Obviously, jetty seems to "understand" the link to the datasource and parses the properties file. But unfortunately, it cannot find the org.h2.Driver class, since it fires an exception:
java.lang.ClassNotFoundException: org.h2.Driver not found by org.eclipse.jetty.security
In fact, I do not know why this dependency to org.h2.Driver cannot be resolved. I start the org.h2 bundle before the jetty bundle, I also tried adding org.h2 as imported package to the jetty bundle, but still get this error.
Does anybode know why jetty cannot resolve this dependency? Any hint?
[Edit] Stacktrace: (realm is my reference to the properties file, where also the driver class (org.h2.driver) is defined)
12:12:57.462 WARN JDBCLoginService UserRealm jdbcrealm could not connect to database; will try later
java.lang.ClassNotFoundException: org.h2.Driver not found by org.eclipse.jetty.security [41]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1550) ~[na:na]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77) ~[na:na]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1988) ~[na:na]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_45]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_45]
at java.lang.Class.forName(Unknown Source) ~[na:1.8.0_45]
at org.eclipse.jetty.security.JDBCLoginService.connectDatabase(JDBCLoginService.java:198) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.JDBCLoginService.loadUser(JDBCLoginService.java:239) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.MappedLoginService.login(MappedLoginService.java:221) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.JDBCLoginService.login(JDBCLoginService.java:223) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.authentication.LoginAuthenticator.login(LoginAuthenticator.java:52) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.authentication.FormAuthenticator.login(FormAuthenticator.java:192) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.authentication.FormAuthenticator.validateRequest(FormAuthenticator.java:229) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:499) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:92) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1099) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:446) ~[org.eclipse.jetty.servlet_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:200) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.Server.handle(Server.java:445) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:269) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) ~[org.eclipse.jetty.io_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) ~[org.eclipse.jetty.util_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) ~[org.eclipse.jetty.util_9.0.6.v20130930.jar:9.0.6.v20130930]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_45]
12:12:57.464 WARN JDBCLoginService UserRealm jdbcrealm could not load user information from database
java.sql.SQLException: Can't connect to database
at org.eclipse.jetty.security.JDBCLoginService.loadUser(JDBCLoginService.java:242) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.MappedLoginService.login(MappedLoginService.java:221) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.JDBCLoginService.login(JDBCLoginService.java:223) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.authentication.LoginAuthenticator.login(LoginAuthenticator.java:52) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.authentication.FormAuthenticator.login(FormAuthenticator.java:192) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.authentication.FormAuthenticator.validateRequest(FormAuthenticator.java:229) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:499) ~[org.eclipse.jetty.security_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:92) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1099) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:446) ~[org.eclipse.jetty.servlet_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:200) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.Server.handle(Server.java:445) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:269) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) ~[org.eclipse.jetty.server_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) ~[org.eclipse.jetty.io_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) ~[org.eclipse.jetty.util_9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) ~[org.eclipse.jetty.util_9.0.6.v20130930.jar:9.0.6.v20130930]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_45]
Regards
Jetty boot uses the classloader of its bundle to resolve any classes from the configuration. To make Jetty see the packages of H2 I can think of one option:
Create a bundle that is the fragment of jetty-boot and imports the necessary package of H2. Your bundle will have only a MANIFEST.MF file with a content like the following:
Bundle-SymbolicName: jettyboot.mix.with.h2
Bundle-Version: 1.0.0
Fragment-Host: org.eclipse.jetty.osgi.boot
Import-Package: org.h2,org.h2.jdbcx
EDIT
Based on the stacktrace, you use JDBCLoginService. I have just had a quick look and it uses Class.forName(className) in its code. I am sorry but it I am sure that this will not work for you.
I am not familiar with this part of Jetty but as much as I see, there is a DataSourceLoginService. That can use a pre-instantiated DataSource so classloading should not be a problem. That could work for you.

SQLNestedException when connection pooling using Tomcat

This is the Resource configuration for the jdbc connection pooling for mysql.
<Resource
abandonWhenPercentageFull="50"
auth="Container"
closeMethod="close"
driverClassName="com.mysql.jdbc.Driver"
global="jdbc/gisdata"
initialSize="34"
logAbandoned="true"
maxActive="377"
maxIdle="233"
maxWait="10000"
minEvictableIdleTimeMillis="55000"
minIdle="89" name="jdbc/gisdata"
password="temp12345"
removeAbandoned="true"
removeAbandonedTimeout="60"
testOnBorrow="true"
timeBetweenEvictionRunsMillis="34000"
type="javax.sql.DataSource"
url="jdbc:mysql://URL:3306/zmaperp_final?allowMultiQueries=true"
username="root"
validationInterval="34000"
validationQuery="SELECT 1"
/>
I get the following error:
WARNING: Unexpected exception resolving reference
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getLogWriter(BasicDataSource.java:1098)
at org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:350)
at org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory.getObjectInstance(BasicDataSourceFactory.java:156)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:141)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
at org.apache.naming.NamingContext.lookup(NamingContext.java:842)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1103)
at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:682)
at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:271)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
I am using the Tomcat instance on my system within Tomcat and have added the mysql-connector jar file as recommended:
UPDATE: I have updated the jar file as suggested by #Jan's answer. The error has changed to look like this:
WARNING: Unexpected exception resolving reference
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Error preloading the connection pool
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1398)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getLogWriter(BasicDataSource.java:1098)
at org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:350)
at org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory.getObjectInstance(BasicDataSourceFactory.java:156)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:141)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
at org.apache.naming.NamingContext.lookup(NamingContext.java:842)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1103)
at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:682)
at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:271)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1112)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2506)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2539)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.addObject(GenericObjectPool.java:1679)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1395)
... 23 more
Update
Updated the connection properties:
<Resource
abandonWhenPercentageFull="50"
auth="Container"
closeMethod="close"
driverClassName="com.mysql.jdbc.Driver"
global="jdbc/gisdata"
initialSize="10"
logAbandoned="true"
maxActive="25"
maxIdle="10"
maxWait="10000"
minEvictableIdleTimeMillis="55000"
minIdle="5"
name="jdbc/gisdata"
password="temp12345"
removeAbandoned="true"
removeAbandonedTimeout="60"
testOnBorrow="true"
timeBetweenEvictionRunsMillis="34000"
type="javax.sql.DataSource"
url="jdbc:mysql:SERVER/zmaperp_final?allowMultiQueries=true"
username="root"
validationInterval="34000" validationQuery="SELECT 1;"
/>
I tried removing the allowMultiQueries option now but the connection is still giving me an error.
You have to add the Driver, not the Sources :-)
Check the file name for your driver. You'll want
mysql-connector-java-5.1.37-bin.jar
or with highlighting: You have mysql-connector-java-5.1.37-source.jar, you need mysql-connector-java-5.1.37-bin.jar
Good luck :-)
Edit / Your Question changed
message from server: "Too many connections"
You need to reduce number of max / initial connections to something moderate. I recommend
maxActive="25"
maxIdle="10"
maxWait="10000"
minEvictableIdleTimeMillis="55000"
minIdle="5"
for starters.

javax.naming.NamingException: Cannot create resource instance - Tried many different ways

I have tried many different ways to fix this issue but it is throwing error as below. We are using CXF Framework to write web services and read data source from context.xml file. It works fine for data source which connects to database or other system source as well but doesn't work for data source con/TestAPI that i am trying to add now. Not sure what is the issue here.
Please help.
FATAL Failed to init resources.
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:146)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at com.us.test.ws.TestImpl.<init>(TestImpl.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
Sep 24, 2014 5:21:01 PM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be /WSTest/rest
Sep 24, 2014 5:21:01 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://ws.test.us.com/}TestImplService from class com.idms.us.test.ws.TestImpl
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Below is the source that i have defined in my context.xml file. Just want to mention that
<Resource SESSIONFACTORY_NAME="session/SessionFactory"
factory="com.dal.controlcenter.factory.ControlCenterFactory"
name="session/ControlCenterFactory"
type="SessionControlCenter"/>
<Resource
scheme="https" host="test-fe5.testnetdata.com" port="8291"
username="user"
password="password"
name="con/TestAPI"
type="java.util.HashMap"/>
<Resource name="jdbc/dataSource" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://somehost:3306/db_database?useOldAliasMetadataBehavior=true"
username="user"
password="!password!"
maxActive="10"
maxIdle="1"
maxWait="120000"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="10000"
minEvictableIdleTimeMillis="60000"
removeAbandoned="true"
removeAbandonedTimeout="300"
noAccessToProcedureBodies="true"
/>
Below is what i have defined web.xml of my project.
<resource-ref>
<description>
some description
</description>
<res-ref-name>
con/TestAPI
</res-ref-name>
<res-type>
java.util.HashMap
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
Below is the code on my java class.
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
splunkAPIConnectionMap = (HashMap) envCtx.lookup("con/TestAPI");
}catch (NamingException ex){
log.fatal("Failed to init resources.", ex);
}

How to configure jndi in tomcat regarding my errors?

I have searched on google and stackoverflow for this problem there are several questions but not resulting to particular solution and reason behind the cause. I am doing a project in JSF with context for my project defined in C:\apache-tomcat-6.0.32\conf\Catalina\localhost\.
Also my in my web.xml I have following configuration:
<context-param>
<description>Database server name</description>
<param-name>DATABASE</param-name>
<param-value>MYSQL</param-value>
</context-param>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Now The context file for this project is as follows:
<Context path="/SMS" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/MySqlDS" auth="Container"
type="javax.sql.DataSource" removeAbandoned="true"
removeAbandonedTimeout="30" maxActive="100"
maxIdle="30" maxWait="10000" username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/rosebud"/>
</Context>
The code in my controller is :
InitialContext initialContext = new InitialContext();
Context envContext = (Context)initialContext.lookup("java:/comp/env");
javax.sql.DataSource ds = (javax.sql.DataSource) envContext.lookup("jdbc/MySqlDS");
java.sql.Connection conn = ds.getConnection();
Here is my stacktrace:
org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create JDBC driver of class ''
for connect URL 'null' at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at
com.isys.common.navigation.dao.mysql.TmpNavDAOMySql.getConnection(TmpNavDAOMySql.java:91)
at
com.isys.common.navigation.dao.mysql.TmpNavDAOMySql.populateModels(TmpNavDAOMySql.java:114)
at
com.isys.common.navigation.dao.mysql.TmpNavDAOMySql.populateNavModules(TmpNavDAOMySql.java:19)
at
com.isys.common.navigation.dao.mysql.TmpNavDAOMySqlImpl.populateNavModules(TmpNavDAOMySqlImpl.java:11)
at
com.isys.common.navigation.controller.TmpNavGenerator.init(TmpNavGenerator.java:12)
at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at
org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4420)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4733)
at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at
org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at
org.apache.catalina.core.StandardService.start(StandardService.java:525)
at
org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at
org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source) at
java.lang.reflect.Method.invoke(Unknown
Source) at
org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at
org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by:
java.lang.NullPointerException at
sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(Unknown
Source) at
sun.jdbc.odbc.JdbcOdbcDriver.knownURL(Unknown
Source) at
sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(Unknown
Source) at
java.sql.DriverManager.getDriver(Unknown
Source) at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 24 more
The configuration works fine if I run tomcat from outside eclipse but fails when ran from inside eclipse. What might be the cause?
Look at the root cause of the exception:
Caused by: java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(Unknown Source)
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 24 more
This NPE is clearly a bug in the Sun JDBC ODBC bridge driver. It should have handled it more gracefully or have thrown a more self-explaining exception.
But it is at its own a bigger problem that the Tomcat datasource manager is using the Sun JDBC ODBC bridge driver instead of the MySQL JDBC driver which you specified in the driverClassName of the <Resource>! This means that the <Resource> is not correctly been found/interpreted by Tomcat at all. You should be placing the context.xml file in the /META-INF folder of your webapp. Or you should be putting the <Resource> inside the <Context> of the tomcat/conf/context.xml file.

jndi database connection with jpa and eclipselink

I try to setup a database connection in java with JNDI in combination with eclipseLink/JPA on Tomcat 5.5. I already configured the JNDI resource in web.xml and context.xml.
The db connection works with JNDI without using JPA and eclipseLink.
After configuring the persistence.xml for eclipseLink, I got the following exception.
I don't know how to configure the persistence.xml correctly to use JNDI datasource for the db connection.
The exception
WicketMessage: Method onFormSubmitted of interface
org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component
[MarkupContainer [Component id = loginForm]] threw an exception
Root cause:
javax.naming.NamingException: This context must be accessed throught a java: URL
at org.apache.naming.SelectorContext.parseName(SelectorContext.java:686)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:121)
at javax.naming.InitialContext.lookup(InitialContext.java:396)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:110)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:16 2)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(Datab aseSessionImpl.java:579)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:380)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:637)
Complete stack:
org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = loginForm]] threw an exception
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:193)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:comp/env/jdbc/myDs].
Internal Exception: javax.naming.NamingException: This context must be accessed throught a java: URL
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:408)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:comp/env/jdbc/myDs].
Internal Exception: javax.naming.NamingException: This context must be accessed throught a java: URL
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:464)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:116)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:579)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:380)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
web.xml
...
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myDs</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
context.xml
...
<Resource
name="jdbc/myDs"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
validationQuery="SELECT 1"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="60000"
minEvictableIdleTimeMillis="600000"
username="root"
password="passwd"
maxWait="10000"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/myDs" />
...
persistence.xml
...
<persistence-unit name="myDs" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/myDs</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<class>de.company.myDS.model.User</class>
</persistence-unit>
...
Just add the class JPAEclipseLinkSessionCustomizer to your project and configure the persistence.xml as shown below:
<persistence-unit name="yourUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/yourDs</non-jta-data-source>
<properties>
<property name="eclipselink.session.customizer" value="com.company.yourproject.yourpackage.JPAEclipseLinkSessionCustomizer"/>
</properties>
</persistence-unit>
You need this workaround only for Apache Tomcat.
Set the datasource URL to "jdbc/myDs"
<non-jta-data-source>jdbc/myDs</non-jta-data-source>
I hope you could solve the problem with the comments given ...
I fix it by adding a property "javax.persistence.nonJtaDataSource" with the same value as the element non-jta-data-source
I think you need to code a workaround for the javax.naming.NamingException: This context must be accessed throught a java: URL exception as detailed at http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer
Also see this link which debugs through the problem
http://forums.java.net/jive/message.jspa?messageID=158622
Year 2015 actualisation: I not sure Eclipselink SessionCustomizer is required. In my test all work without (Tomcat 7.x, Java 7.x, Eclipselink 2.4.x).
Some older materials suggest specific problem with Tomcat 5/6 and special way to resolve it.

Categories