Can't find mysql.jdbc.Driver - MySQL, JBoss - mysql

I'm unable to deploy my web app with MySQL 5.5.11 backend to JBoss 5. I get this error:
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310
I pasted my stack trace below.
Here's what I've done...
I added mysql-connector-java-5.1.14-bin.jar to {JBOSS_HOME}/lib (that connector should work with MySQL 5.5.11 right?). I also added mysql-ds.xml to {JBOSS_HOME}/server/default/deploy.
<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/my_libl_db</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>test</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
</local-tx-datasource>
</datasources>
Also, I made sure the mysql-connector-java-5.1.14-bin.jar in my lib folder is in my web apps classpath. In the JBoss Admin Console, under Resources/Datasources, I do see MySqlDS with a status of up.
My project (in Eclipse Indego Release) is an Enterprise Application Project with 1 Dynamic Web Project. The web app has has an #Entity bean and a #Stateless bean. The #Stateless is being injected to a servlet (using #EJB). Here's my persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="ContactBookPersistUnit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MySqlDS</jta-data-source>
<class>com.contact.model.Contact</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
What could I be doing wrong?
Caused by: javax.resource.ResourceException: Unable to get managed connection for MySqlDS
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:441)
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:381)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:496)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:941)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
... 65 more
Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: com.mysql.jdbc.Driver; - nested throwable: (java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310{VFSClassLoaderPolicy#5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain#5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader#7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler#150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]] delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}}))
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:225)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:195)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:633)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:267)
at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:622)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:404)
... 69 more
Caused by: org.jboss.resource.JBossResourceException: Failed to register driver for: com.mysql.jdbc.Driver; - nested throwable: (java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310{VFSClassLoaderPolicy#5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain#5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader#7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler#150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]] delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}})
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:489)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:206)
... 74 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310{VFSClassLoaderPolicy#5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain#5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader#7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler#150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]] delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}}
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:448)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:474)

This bit of documentation says you need to add the JAR to the /lib file in your default server configuration:
http://docs.jboss.org/jbossas/getting_started/v4/html/db.html
UPDATE: JBOSS 6 and newer has been rewritten to be more modular. You have to add JBDC drivers to your /module directory.

Related

Unable to build Hibernate SessionFactory

in a jakarta - wildfly project when i try to run the project this error message appears.
Deploying on WildFly Application Server
profile mode: false
debug mode: false
force redeploy: true
Undeploying ...
Initial deploying EutopeanDynamics-shop-2022 to C:\Program Files\wildfly-27.0.1.Final\standalone\deployments\WebEshop.war
Completed initial distribution of EutopeanDynamics-shop-2022
Deploying C:\Program Files\wildfly-27.0.1.Final\standalone\deployments\WebEshop.war
"{\"WFLYCTL0080: Failed services\" => {\"jboss.persistenceunit.\\\"WebEshop.war#Persistence\\\"\" => \"jakarta.persistence.PersistenceException: [PersistenceUnit: Persistence] Unable to build Hibernate SessionFactory
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: Persistence] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
Caused by: java.sql.SQLException: jakarta.resource.ResourceException: IJ000453: Unable to get managed connection for java:/MySqlDS
Caused by: jakarta.resource.ResourceException: IJ000453: Unable to get managed connection for java:/MySqlDS
Caused by: jakarta.resource.ResourceException: IJ031084: Unable to create connection
Caused by: java.sql.SQLException: Access denied for user 'admin'#'localhost' (using password: YES)\"}}"
Here is my persistence class
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="Persistence" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/MySqlDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.globally_quoted_identifiers" value="true"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
I am using wildfly application server. The server is running and from localhost:9990 i created a datasource pointing in an empty database called 'eshop" as shown in the image above
enter image description here

Mysql Driver class com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation from wildfly

maybe my setup is quite special, but I do have issues when I define a JDBC Datasource for Java EE container in my web.xml file.
I configured my Datasource in my web.xml as follow:
<data-source>
<name>java:app/myapp/DS</name>
<class-name>com.mysql.jdbc.Driver</class-name>
<url>jdbc:mysql://localhost:3306/database?useSSL=false&allowPublicKeyRetrieval=true</url>
<user>foo</user>
<password>pass</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
<initial-pool-size>2</initial-pool-size>
<max-pool-size>10</max-pool-size>
<min-pool-size>5</min-pool-size>
<max-statements>0</max-statements>
</data-source>
After I use datasource's name as my jta-data-source in my persistence file as follow:
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="java-rs-with-hibernate" transaction-type="JTA">
<jta-data-source>java:app/myapp/DS</jta-data-source>
<class>com.patrickhub.ch.java_rs_with_hibernate.domain.Product</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="none"/>
<property name="javax.persistence.schema-generation.scripts.action" value="none"/>
</properties>
</persistence-unit>
</persistence>
And in my code I used the EntityManager to make request to the database.
But when I deploy it to wildfly 18.0.1, I get the following errors:
at org.jboss.as.connector#18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:174)
at org.jboss.msc#1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jboss.msc#1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
at org.jboss.msc#1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1363)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.jboss.jca.deployers.common.DeployException: WFLYJCA0030: unable to deploy
at org.jboss.as.connector#18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer.deploy(AbstractDataSourceService.java:376)
at org.jboss.as.connector#18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:160)
... 8 more
Caused by: org.jboss.as.controller.OperationFailedException: WFLYJCA0117: com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation [ "WFLYJCA0117: com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation" ]
... 10 more
I think that if I replace com.mysql.jdbc.Driver with com.mysql.jc.jdbc.Driver, it will deploy successfully but I still have the same problem and the same message error.
I don't know if I miss something on how to define a mysql JDBC datasource in web.xml file. but I think it is correct.
Please can someone help me.

Connect a web-app on tomcat container to mysql container via hibernate

i'm trying to port my web-app from windows (using xampp for apache+mysql) to ubuntu (using docker container, so i have two containers: one with tomcat and another one with mysql.. they're linked).
Related to this question, i can't reach my sql container. It's creted from this image.
Tomcat container is created from official tomcat:8.0 image.
The two container are linked via a bridge docker network created.
It's a web-app that provides login+register service with checking user's presence in db.
I have to tell that on windows all works well.
This is my hibernate.cfg file:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- queste configurazioni sono per il testing in locale -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:49162/AT_DB</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">lxit</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">false</property>
<!--<property name="hibernate.hbm2ddl.auto">create-drop</property> se al posto di update metto create, mi cancella il db e lo rifa -->
<property name="hbm2ddl.auto">update</property>
<!-- Entity -->
<mapping class="com.ATBoscoCastellano.Entity.ClientUser" />
<mapping class="com.ATBoscoCastellano.Entity.GenericUser" />
<mapping class="com.ATBoscoCastellano.SessionManagement.SessionToken" />
<mapping class="com.ATBoscoCastellano.Entity.Post" />
<!-- <mapping class="it.boscus.StarFoods.entity.ExampleEmbeddableIDClass2" /> -->
</session-factory>
</hibernate-configuration>
After i insert my credential, i click on "login"; then there is a servlet named "UserSessionServlet" that checks if in the db is present an user with that credential; the error appairs when i click login, because UserSessionServlet return http 500 error.
[Edit] On tomcat container, i saw that logs tell me:
16-Feb-2017 09:43:41.498 SEVERE [http-nio-8080-exec-19] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [com.ATBoscoCastellano.servlets.UserSessionServlet] in context with path [/AtApplicazione1] threw exception [Servlet execution threw an
exception] with root cause
java.lang.NoClassDefFoundError: Could not initialize class com.ATBoscoCastellano.Util.HibernateUtil.HibernateUtil
at com.ATBoscoCastellano.Entity.GenericUser.checkIfUserExistsByEmail(GenericUser.java:198)
at com.ATBoscoCastellano.Entity.ClientUser.validateCredentials(ClientUser.java:259)
at com.ATBoscoCastellano.servlets.UserSessionServlet.doPost(UserSessionServlet.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
But all these classes exist, under opt/tomcat/webapps/AtApplicazione1/WEB-INF/classes/com/AtBoscoCastellano/some/paths.
I have to tell that i've not modified my tomcat container from official image (tomcat:8.0), so i can't know if it's configured for hibernate or not.
My war is structured as follows: three folders (META-INF, WEB-INF, template) and a file (.DS_Store). Because of my exception is :java.lang.NoClassDefFoundError: Could not initialize class com.ATBoscoCastellano.Util.HibernateUtil.HibernateUtil , in the war, this class is under WEB-INF/classes/com/ATBoscoCastellano/Util/HibernateUtil/ ... in which there is HibernateUtil .class and .java.
When i cmd java/javac -version on my tomcat container, its output is:
root#a26ff8018f3f:/opt/tomcat# java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
root#a26ff8018f3f:/opt/tomcat# javac -version
javac "1.8.0_111"
[re-edit]: in my first requests, catalina logs says java.net.ConnectException: Connection refused; then, from the second request, it says to me always the same error.
[EDIT] now i'm using a new mysql container, named mysql-phpmyadmin from this image. I've linked tomcat container to this (new) container,; if i point, in the hibernate.cfg.xml, to localhost:PORT_MYSQL/AT_DB --> connection refused in tomcat log. If i point to mysql-phpmyadmin:PORT/AT_DB, tomcat logs says:
17-Feb-2017 08:31:25.649 SEVERE [http-apr-8080-exec-2] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [com.ATBoscoCastellano.servlets.UserSessionServlet] in context with path [/AtApplicazione1] threw exception [Servlet execution threw an e
xception] with root cause
java.sql.SQLException: null, message from server: "Host '172.17.0.9' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:959)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1038)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2254)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2285)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2084)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
I have to tell that, in config file within mysql container, there is bind_address 0.0.0.0
I think I have an idea why you are getting this exception. You are running 2 containers,
mysql container for data base
Tomcat container
Surely, your exception is due to static variable initialization exception,
public static final SessionFactory sessionFactory = buildSessionFactory();
Also, your property file has few problems,
connection.url should be hibernate.connection.url
You have mentioned your mysql hostname as localhost but it is running in another container. You should change it to "mysql" if you have named your mysql container as "mysql"
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:214)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
Clearly shows that your either
Mysql is not runnning. Check by making a connection from sql client like squirrel.
Tomcat container can't connect to mysql container. Check a quick ping by doing
docker exec tomcat ping mysql
Took me a while to deploy this application. I have solved the problem you have asked in this question. The primary problem was that mysql was not reachable from tomcat container. Also, the port specified was also not correct. Following is hibernate.cfg.xml,
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- queste configurazioni sono per il testing in locale -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://mysql:3306/AT_DB</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">lxit</property>
....rest of configuration....
</session-factory>
</hibernate-configuration>
There are few problems like following,
17-Feb-2017 16:07:53.156 INFO [http-nio-8080-exec-1] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
17-Feb-2017 16:07:53.776 INFO [http-nio-8080-exec-1] org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults HHH000262: Table not found: ClientUser
17-Feb-2017 16:07:53.777 INFO [http-nio-8080-exec-1] org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults HHH000262: Table not found: ClientUser
17-Feb-2017 16:07:53.818 INFO [http-nio-8080-exec-1] org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults HHH000262: Table not found: Post
17-Feb-2017 16:07:53.819 INFO [http-nio-8080-exec-1] org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults HHH000262: Table not found: Post
17-Feb-2017 16:07:53.828 INFO [http-nio-8080-exec-1] org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults HHH000262: Table not found: SessionToken
17-Feb-2017 16:07:53.828 INFO [http-nio-8080-exec-1] org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults HHH000262: Table not found: SessionToken
17-Feb-2017 16:07:53.830 WARN [http-nio-8080-exec-1] org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl.handleException GenerationTarget encountered exception accepting command : Unable to execut
But these are due to case sensitivity of unix which was probably not there in case of Windows. Rest of the exception are trivial to solve. I ran following docker commands,
sudo docker run -ti --rm -p 8888:8080 -p 8009:8009 -v $(pwd):/usr/local/tomcat/webapps/ --name tomcat tomcat:9-jre8 bash
sudo docker run -d --name mysql -p 49162:3306 -p 49161:80 -p 49160:22 lxitgto/mysql-phpmyadmin:v1
and rest of the network command.

JBOSS 7 MYSQL missing dependencies error

There are many threads like this one already for similar errors but none which have solved my problem so after an hour of trying to debug it, I have decide to ask for help.
Background
I am setting up a Java EE project. I have create an enterprise application and have create an EJB project, JPA project and web Project and added EAR's to the enterprise project.
I have also added mysql-connector-java-5.1.0-bin to the JBOSS/standalone/deployments folder. And added to this jar file to the JPA project.
Any advice on how to solve the error would be greatly apprecited.
The main error is:
missing/unavailable dependencies" =>
["jboss.persistenceunit.\"SIMSProject.ear#primary\"jboss.naming.context.java.jboss.datasources.SIMSD
Here is my full error:
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "org.hibernate:main" from local module loader #32008dad (roots: C:\Users\Bawn92\Desktop\Programs\jboss-as-7.1.1.Final\modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_07]
at java.lang.Class.forName(Class.java:186) [rt.jar:1.7.0_07]
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:101)
... 23 more
01:50:40,265 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "SIMSProject.ear" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"SIMSProject.ear#SIMSJPA\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"SIMSProject.ear#SIMSJPA\": Failed to start service"},"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"SIMSProject.ear#primary\"jboss.naming.context.java.jboss.datasources.SIMSDBMissing[jboss.persistenceunit.\"SIMSProject.ear#primary\"jboss.naming.context.java.jboss.datasources.SIMSDB]"]}
01:50:40,296 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment SIMSWebProject.war in 31ms
01:50:40,296 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment SIMSEJB.jar in 31ms
01:50:40,309 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment SIMSProject.ear in 44ms
01:50:40,312 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.persistenceunit."SIMSProject.ear#SIMSJPA": org.jboss.msc.service.StartException in service jboss.persistenceunit."SIMSProject.ear#SIMSJPA": Failed to start service
01:50:40,316 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.persistenceunit.\"SIMSProject.ear#SIMSJPA\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"SIMSProject.ear#SIMSJPA\": Failed to start service"},"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"SIMSProject.ear#primary\"jboss.naming.context.java.jboss.datasources.SIMSDBMissing[jboss.persistenceunit.\"SIMSProject.ear#primary\"jboss.naming.context.java.jboss.datasources.SIMSDB]"]}}}
MY -ds.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jndi-name="java:jboss/datasources/SIMSDB" enabled="true"
use-java-context="true" pool-name="SIMSDB">
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver>mysql-connector-java-5.1.0-bin.jar</driver>
<pool></pool>
<security>
<user-name>root</user-name>
<password>nbuser</password>
</security>
</datasource>
</datasources>
My persistence.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/SIMSDB</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
<persistence-unit name="SIMSJPA">
<class>model.Class</class>
<class>model.Subject</class>
<class>model.Teacher</class>
<properties>
<!-- //i put in dialect line -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="nbuser"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
The datasourse section of my Standalone file is:
<datasource jndi-name="java:jboss/datasources/SIMSDB" pool-name="SIMSDB">
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver>mysql-connector-java-5.1.0-bin.jar</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>test</user-name>
<password>test</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
<drivers>
<driver name="com.mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
You need to create MySQL driver module.
JBoss 7 will be able to use if you create it like this:
download the driver (jar file)
create directory in you server path: {$jboss-home}/modules/com/mysql/main
and paste the driver jar file here
in same folder create and new file module.xml
Insert following code in that module.xml (if your jar file is named mysql.jdbc.jar):
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql.jdbc.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Make sure the dependencies for your mysql.jdbc.jar are OK.
JBoss 7 is not using -ds.xml any more.
You allready doing setup for your databse in standalon.xml, this the right way.
Just make sure your migration is correct. I see you have diffent user name and password...
EDIT1:
I don't know how hibernate works with JBoss 7.
But I see you should try to change in your persistence.xml
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
to
<property name="hibernate.connection.driver_class" value="com.mysql"/>
because you are using com.mysql as module name. Otherwise you can change module name to com.mysql.jdbc.Driver.
In your standalone.xml
change
<driver>mysql-connector-java-5.1.0-bin.jar</driver>
to
<driver>com.mysql</driver>
because you gave com.mysql as name for your driver:
<driver name="com.mysql" module="com.mysql">

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