Connection pool issue: Connection has already been closed - mysql

I am using Grails 2.4.2, Tomcat 7 and MySQL 5.6.17 and I am having problem with the connection pool. After a while my application randomly reports the following errors.
2014-07-24 08:24:35,012 [http-bio-127.0.0.1-50000-exec-9] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Connection has already been closed.
and
2014-07-25 10:55:12,018 [http-bio-127.0.0.1-50000-exec-6] ERROR org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver - SQLException occurred when processing request: [GET] /controller/index
Connection has already been closed.. Stacktrace follows:
java.sql.SQLException: Connection has already been closed.
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:189)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Here is the JNDI datasource resource defined in $TOMCAT_HOME/conf/context.xml
<Resource name="jdbc/xxx" auth="Container" type="javax.sql.DataSource"
username="user" password="password"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
url="jdbc:mysql://localhost:3306/db?generateSimpleParameterMetadata=true"
validationQuery="SELECT 1"
validationInterval="30000"
initialSize="5"
maxActive="50"
minIdle="5"
maxIdle="30"
maxWait="10000"
timeBetweenEvictionRunsMillis="5000"
minEvictableIdleTimeMillis="55000"
testOnBorrow="true"
removeAbandoned="true"
removeAbandonedTimeout="55"/>
Does anyone of you have any experience on this topic and can help me on this?

Switching to C3P0 connection pool did the job.
<Resource auth="Container"
description="DB Connection"
driverClass="com.mysql.jdbc.Driver"
maxPoolSize="10"
minPoolSize="2"
acquireIncrement="1"
name="jdbc/xxx"
user="user"
password="password"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/db?generateSimpleParameterMetadata=true" />

Related

SpringBoot Mysql Database Unable to open JDBC Connection for DDL execution

I got my application running with using a local h2 database. Now I want to connect it to an online mysql database. But when trying to start the connection, I get com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure several times and in addition the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at quiz.QuizAppMain.main(QuizAppMain.java:16) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.0.RELEASE.jar:2.0.0.RELEASE]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:970) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:895) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:388) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
... 21 common frames omitted
Caused by: org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:69) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl.getJdbcConnection(ImprovedExtractionContextImpl.java:60) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl.getJdbcDatabaseMetaData(ImprovedExtractionContextImpl.java:67) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTables(InformationExtractorJdbcDatabaseMetaDataImpl.java:329) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTablesInformation(DatabaseInformationImpl.java:120) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:65) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:312) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:460) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
... 28 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
I added the following to my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
And this to my application.properties:
spring.datasource.url=jdbc:mysql://my.url.net:port
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.name=dbname
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
When changing from h2 to mysql I did not do any changes on my sourcecode since I'm implementing the CrudRepository that should also work with mysql.
Could you give me some hints what might be missing? I already checked similar questions here on stackoverflow, but after adding several solution approaches (e.g. adding the hibernate.dialect and driver-class-name) my application is still not working.
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
You need to modify the dialect based on the version of mysql running.
MySql 5.5 - org.hibernate.dialect.MySQL55Dialect
MySql 5.7 - org.hibernate.dialect.MySQL57Dialect
MySql 8 - org.hibernate.dialect.MySQL8Dialect
You can check MySql version using this query
SHOW VARIABLES LIKE "%version%";
and check InnoDB version
Thanks!! I've head the same probleme and resolve it using your answer:
1) First I chekcked MySql version with
SHOW VARIABLES LIKE "%version%";
2) Then modified the dialect using the right one:
MySql 5.5 - org.hibernate.dialect.MySQL55Dialect
MySql 5.7 - org.hibernate.dialect.MySQL57Dialect
MySql 8 - org.hibernate.dialect.MySQL8Dialect
And it worked!
Replace these properties into your app.prop file.
# Connection url for the database "netgloo_blog"
spring.datasource.url = jdbc:mysql://localhost:3306/your_db_name?useSSL=false
# Username and password
spring.datasource.username = username
spring.datasource.password = password
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Spring data jpa Auditor <jpa:auditing auditor-aware-ref="customAuditorAware"/>
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Datasource url should be:
spring.datasource.url=jdbc:mysql://localhost/database?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
Just add the following line to your project property file.
spring.jpa.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
I know this is an old thread. Just updating this in case someone else is facing the same issue.
As written in the error message - org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution, this is a Generic JDBC exception and unlike what it sounds, this does not always mean that it is unable to establish a connection.
In my case, I was using a different datasource with H2 for unit testings and all. What I found out is that I gave a wrong classpath in H2 DB schema creation command. This same error message is also generated if there is nay query error while table creaion in while H2 start up.
Best possible solution for this is to just run it in debug mode and find out what is causing this issue.

web services.Error: com.mysql.jdbc.CommunicationsException: Communications link failure java.io.EOFException [duplicate]

My webapp is running on Tomcat 5.5, I declared the datasource in web.xml:
<resource-ref>
<res-ref-name>jdbc/OrdiniWebDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
In context.xml (tomcat conf):
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/OrdiniWebDS"
password="[mypassword]"
type="javax.sql.DataSource"
url="jdbc:mysql://[myHost:port]/ordiniweb"
username="[myusername]"
/>
The database is a MySql 5.0.
Everything works well except that sometimes, after several hours of "unuse", at first access I got this Exception:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1956)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2579)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
I need to refresh and it works well again. Any idea? Thanks.
MySQL drops unused connections after a while because it assumes that the other side forgot to close it.
What you need to do is to configure a check that Tomcat should apply before it reuses a pooled connection. To do this, add ?autoReconnect=true&useUnicode=true&characterEncoding=utf8 to the end of the URL and add validationQuery="Select 1" to the Resource element:
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/OrdiniWebDS"
password="[mypassword]"
type="javax.sql.DataSource"
url="jdbc:mysql://[myHost:port]/ordiniweb?autoReconnect=true&useUnicode=true&characterEncoding=utf8"
username="[myusername]"
validationQuery="Select 1"
/>
[EDIT] This page gives more details: Configuring a MySQL Datasource in Apache Tomcat

Trying to install HikariCP on tomcat 7 and getting javax.naming.NamingException on startup

I am trying to configure HikariCP as my datasource connection pool on tomcat 7 with mysql. Here is my context file...
<?xml version="1.0" encoding="UTF-8"?>
<Context allowCasualMultipartParsing="true">
<Resource name="jdbc/application" auth="Container"
factory="com.zaxxer.hikari.HikariJNDIFactory"
type="javax.sql.DataSource"
minimumIdle="5"
maximumPoolSize="10"
connectionTimeout="300000"
dataSource.implicitCachingEnabled="true"
dataSource.user="root"
dataSource.password="pass"
dataSource.url="jdbc:mysql://localhost:3306/Database"/>
</Context>
But on startup I get this error...
WARNING: Failed to retrieve JNDI naming context for container
javax.naming.NamingException: No naming context bound to this class loader
How can I configure HikariCP-2.3.0 on tomcat?
may be this could help you
Configuring the Tomcat Definitions
Location of your JNDI datasource definitions depends upon the scope for the connections. You can define them globally by specifying them in Tomcat's conf/server.xml and conf/context.xml, or you can scope them to individual applications by defining them in conf/Catalina/localhost/WebAppContext.xml (where WebAppContext is the web application context for the app, basically the directory name from Tomcat's webapps directory).
<Resource name="jdbc/LiferayPool" auth="Container"
factory="com.zaxxer.hikari.HikariJNDIFactory"
type="javax.sql.DataSource"
minimumIdle="5"
maximumPoolSize="10"
connectionTimeout="300000"
dataSourceClassName="org.postgresql.ds.PGSimpleDataSource"
dataSource.url="jdbc:postgresql://localhost:5432/lportal"
dataSource.implicitCachingEnabled="true"
dataSource.user="user"
dataSource.password="pwd" />
https://community.liferay.com/blogs/-/blogs/tomcat-hikaricp

JBoss server exception while connecting to mysql

I have recently tried JPA program with jboss and eclipse. For connecting to MySQL i have put in the required mySQL-connector JAR in the JBoss installation directory path and I have added the configuration in the standalone.xml of jboss and with that if i start the jboss from eclipse it starts up fine and it shows me the configured connection as well.
But if i add my ejb program and start the server it is giving me the following error and when i searched to solve this, each of the forum is giving me different solutions, but nothing seems to address my problem.
ERROR
17:34:17,195 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service
jboss.deployment.unit."FirstEJBProject.jar".INSTALL:
org.jboss.msc.service.StartException in service
jboss.deployment.unit."FirstEJBProject.jar".INSTALL: Failed to process
phase INSTALL of deployment "FirstEJBProject.jar" at
org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119)
[jboss-as-server-7.1.1.Final.jar:7.1.1.Final] at
org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
[jboss-msc-1.0.2.GA.jar:1.0.2.GA] at
org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
[jboss-msc-1.0.2.GA.jar:1.0.2.GA] at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[rt.jar:1.7.0_13] at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[rt.jar:1.7.0_13] at java.lang.Thread.run(Unknown Source)
[rt.jar:1.7.0_13] Caused by: java.lang.IllegalArgumentException: Empty
name segment is not allowed for java at
org.jboss.msc.service.ServiceName.of(ServiceName.java:85)
[jboss-msc-1.0.2.GA.jar:1.0.2.GA] at
org.jboss.msc.service.ServiceName.append(ServiceName.java:112)
[jboss-msc-1.0.2.GA.jar:1.0.2.GA] at
org.jboss.as.naming.deployment.ContextNames.buildServiceName(ContextNames.java:178)
at
org.jboss.as.naming.deployment.ContextNames$BindInfo.(ContextNames.java:190)
at
org.jboss.as.naming.deployment.ContextNames$BindInfo.(ContextNames.java:181)
at
org.jboss.as.naming.deployment.ContextNames.bindInfoFor(ContextNames.java:124)
at
org.jboss.as.naming.deployment.ContextNames.bindInfoForEnvEntry(ContextNames.java:165)
at
org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deployPersistenceUnit(PersistenceUnitDeploymentProcessor.java:319)
at
org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:258)
at
org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.handleJarDeployment(PersistenceUnitDeploymentProcessor.java:145)
at
org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deploy(PersistenceUnitDeploymentProcessor.java:120)
at
org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113)
[jboss-as-server-7.1.1.Final.jar:7.1.1.Final] ... 5 more
17:34:17,430 INFO [org.jboss.as.server] (DeploymentScanner-threads -
2) JBAS015870: Deploy of deployment "FirstEJBProject.jar" was rolled
back with failure message {"JBAS014671: Failed services" =>
{"jboss.deployment.unit.\"FirstEJBProject.jar\".INSTALL" =>
"org.jboss.msc.service.StartException in service
jboss.deployment.unit.\"FirstEJBProject.jar\".INSTALL: Failed to
process phase INSTALL of deployment
\"FirstEJBProject.jar\""},"JBAS014771: Services with
missing/unavailable dependencies" =>
["jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.Validatorjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogicMissing[jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.Validatorjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic]","jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.ValidatorFactoryjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogicMissing[jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.ValidatorFactoryjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic]"]}
17:34:17,430 INFO [org.jboss.as.server.deployment] (MSC service
thread 1-2) JBAS015877: Stopped deployment FirstEJBProject.jar in 13ms
17:34:17,445 INFO [org.jboss.as.controller]
(DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic
(missing) dependents: [service
jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.ValidatorFactory,
service
jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.Validator]
JBAS014777: Services which failed to start: service
jboss.deployment.unit."FirstEJBProject.jar".INSTALL:
org.jboss.msc.service.StartException in service
jboss.deployment.unit."FirstEJBProject.jar".INSTALL: Failed to process
phase INSTALL of deployment "FirstEJBProject.jar"
17:34:17,461 ERROR [org.jboss.as.server.deployment.scanner]
(DeploymentScanner-threads - 1) {"JBAS014653: Composite operation
failed and was rolled back. Steps that failed:" => {"Operation step-2"
=> {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"FirstEJBProject.jar\".INSTALL" =>
"org.jboss.msc.service.StartException in service
jboss.deployment.unit.\"FirstEJBProject.jar\".INSTALL: Failed to
process phase INSTALL of deployment
\"FirstEJBProject.jar\""},"JBAS014771: Services with
missing/unavailable dependencies" =>
["jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.Validatorjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogicMissing[jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.Validatorjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic]","jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.ValidatorFactoryjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogicMissing[jboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic.ValidatorFactoryjboss.naming.context.java.comp.FirstEJBProject.FirstEJBProject.StudentLogic]"]}}}
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<!-- MySQL DataSource -->
<persistence-unit name="STUD">
<jta-data-source>java:/</jta-data-source>
<properties>
<property name="showSql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
sstandalone.xml
<datasource jndi-name="java:/mydb" pool-name="my_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/myschema</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
<statement>
<prepared-statement-cache-size>
100
</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql"/>
</drivers>
</datasources>
Am I missing something here.
I have tried using mySQL-ds.xml and if i use that it is giving a different error as the datasource is unresolvable. It will be helpful if i know the solution for that as well since will packaging my program and deploying there is no need for me to do the SQL connections in the JBoss again.
Thank You.
The problem was with the <jta-data-source>java:/</jta-data-source> I need to fill in the same name as i have provided in <datasource jndi-name="java:/mydb" so finally fixed it myself, thank you for everyones help.
The fixed persistence XML code
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<!-- MySQL DataSource -->
<persistence-unit name="STUD">
<jta-data-source>java:/mydb</jta-data-source>
<properties>
<property name="showSql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
Hope this will help
You will need to define <driver>mysql</driver. This is typically done by defining a module. You can find all about it here http://bnlconsulting.com/index.php/blog/item/88-jboss-71-adding-mysql-datasource

Cannot create resource instance in Tomcat7

I'm trying to configure connection pool in Tomcat 7. Here is code:
part of server.xml:
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource
name="jdbc/testDataSource"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/delta_server"
username="test" password="test"
validationQuery="select count (*) from session_contexts"
/>
web.xml configuration:
<resource-ref>
<description>
Sample JNDI DataSource resource reference
</description>
<res-ref-name>jdbc/testDataSource</res-ref-name>
<res-type>java.sql.DatSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and access from jsp page:
Context initialContext = new InitialContext();
Context envContext = (Context) initialContext.lookup("java:/comp/env");
conn = (Connection) envContext.lookup("jdbc/testDataSource");
But unfortunately I get exception:
javax.naming.NamingException: Cannot create resource instance
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:146)
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
org.apache.naming.NamingContext.lookup(NamingContext.java:826)
org.apache.naming.NamingContext.lookup(NamingContext.java:145)
org.apache.naming.NamingContext.lookup(NamingContext.java:814)
org.apache.naming.NamingContext.lookup(NamingContext.java:159)
org.apache.jsp.index_jsp._jspService(index_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
How can I fix it?
Thank you.
Your configuration looks pretty much OK (except for some typos in your web.xml file; the <res-type>java.sql.DatSource</res-type> should be <res-type>javax.sql.DataSource</res-type>).
But the problem I think is the fact that you are declaring the database resource inside the server.xml file.
Normally the application resources should be declared in the context.xml file of the application and only be declared in server.xml if they are shared between applications. So my suggestion is to declare the jdbc/testDataSource resource in your context.xml file. That should be one way to make it work.
If you must absolutely have a global resource then in your context.xml file you must add a resource link to it or it won't be visible by default.
This context is distinct from the per-web-application JNDI contexts described in the JNDI Resources HOW-TO. The resources defined in this element are not visible in the per-web-application contexts unless you explicitly link them with <ResourceLink> elements.
So the second way to make it work is to leave the resource declared in server.xml but then add something like this in your context.xml file:
<ResourceLink global="jdbc/testDataSource"
name="jdbc/testDataSource"
type="javax.sql.DataSource" />