Unable to setup MySQL data source in JBoss 7.1.1 - mysql

I am working on a Spring MVC app using sprint MVC 4, MySQL and JBoss 7.1.1. I am trying to set MySQL data source in JBoss.
I have created a file 'module.xml' in JBoss 7.1.1\modules\com\mysql\main directory. Also I have copied mysql-connector-java-5.1.17-bin.jar in same directory. Following is the content of module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-rootpath="mysql-connector-java-5.1.17-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction"/>
</dependencies>
</module>
Following is the data source section in standalone.xml:
<subsystem xmlns="urn:jboss:domain:configadmin:1.0"/>
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jta="true" jndi-name="java:/MySqlDS" pool-name="MySQLPoolFirstPoolName" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://xxx.xxx.xxx.xxx:3306/dbname</connection-url>
<driver>com.mysql</driver>
<pool>
<max-pool-size>30</max-pool-size>
</pool>
<security>
<user-name>xxxxxxxxxx</user-name>
<password>xxxxxxxxxxx</password>
</security>
</datasource>
<drivers>
<driver name="com.mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
When I start JBoss, it shows following error:
New missing/unsatisfied dependencies:
service jboss.jdbc-driver.com_mysql (missing) dependents: [service jboss.data-source.java:/MySqlDS]
I have tried many solutions from web, but not able to resolve this.

Try add the driver-class to datasource configuration.
Eg:
<datasources>
<datasource jta="true" jndi-name="java:/MySqlDS" pool-name="MySQLPoolFirstPoolName" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://xxx.xxx.xxx.xxx:3306/dbname</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>com.mysql</driver>
<pool>
<max-pool-size>30</max-pool-size>
</pool>
<security>
<user-name>xxxxxxxxxx</user-name>
<password>xxxxxxxxxxx</password>
</security>
</datasource>
<drivers>
<driver name="com.mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
</drivers>
</datasources>
I hope this help.

Related

wildfly 10.1 mysql replication second database is read-only exception

I started using Wildfly 10.1 and use mysql as a database. I have two databases, DB1 and DB2. Wildfly will connect to DB2 when D1 disconnected. I've done it so far. But when I connect to DB2, I get a "Connection is read-only" error. I looked at the topic here Database Fail Over in Jboss Data sources but
> <connection-property name = "readOnly"> false </ connection-property>
not resolve. I'm looking for a solution to that. I want master/master not master/slave. In my mysql configuration in standalone.xml:
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="true" jndi-name="java:jboss/datasources/RailbaseLabDS" pool-name="RailbaseLabDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://IP1:3306,IP2:3306/DBN?autoreconnect=true</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql</driver>
<url-delimiter>|</url-delimiter>
<security>
<user-name>DBN</user-name>
<password>DBN</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<background-validation>true</background-validation>
<background-validation-millis>5000</background-validation-millis>
</validation>
</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">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>

"WFLYJCA0041: Failed to load module for driver [com.mysql]" on Jboss 7 with MySQL database

I am creating a web application for JBoss EAP 7 and trying to connect to MySQL 8.0 database.
Am getting the error as
[org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 39) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "datasources"),
("jdbc-driver" => "mysql")]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"
My module.xml file in \jboss-eap-7.1.0\modules\system\layers\base\com\mysql\main is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-8.0.12" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And placed "mysql-connector-java-8.0.12.jar" in \jboss-eap-7.1.0\modules\system\layers\base\com\mysql\main path where module.xml exist.
Datasource configuraion is:
<datasources>
<datasource jta="true" jndi-name="java:jboss/datasources/jdbc/sdmspool" pool-name="sdmspool" enabled="true" use-java-context="true">
<connection-url>jdbc:sqlserver://database;databaseName = sdms</connection-url>
<driver>mysql-connector-java-8.0.12</driver>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
</datasource>
<drivers>
<driver name="mysql-connector-java-8.0.12" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
Can anyone help me in solving this?
Try creating the module by using jboss-cli as follows:
Run the below commands:
./jboss-cli.sh (this will start cli in disconnected mode,in the same mode run the below command)
module add --name=com.mysql --resources=/path/to/mysql.jar --dependencies=javax.api,javax.transaction.api
and then try adding respective driver in your eap configuration.
You don't have to explicitly define driver-class and xa-datasource-class.
resource root path should be as well mysql-connector-java-8.0.12.jar
please note that the extension (.jar) is missing in your xml config

How do I configure our MySQL ReplicationDriver for our JBoss 7 data source?

We’re using MySql 5.5.37 and JBoss 7.1.3, and mysql-connector-java-5.1.22-bin.jar. How do I configure my JBoss’ standalone.xml datasource to connect to our master-slave configuration for MySQL? I tried the below
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql:replication//master.amazonaws.com:3306,slave.amazonaws.com:3306/dbsid?failOverReadOnly=true;roundRobinLoadBalance=true</connection-url>
<driver>mysql</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>sb</user-name>
<password>sb</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.ReplicationDriver</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
But when I restart my server, I get the exception …
Caused by: javax.resource.ResourceException: Wrong driver class [class com.mysql.jdbc.Driver] for this connection URL [jdbc:mysql:replication//master.amazonaws.com:3306,slave.amazonaws.com:3306/dbsid?failOverReadOnly=true;roundRobinLoadBalance=true]
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:256)
... 47 more
I opened my JAR and verified the ReplicationDriver class is in there. Not sure what else I should be trying.
For me this works:
<driver name="com.mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
Not sure why I was messing around with xa-datasource-class elements, but what worked for me was
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.ReplicationDriver</driver-class>
</driver>
The driver implementation is selected based on the connect-url.
If you specify a connection url like this: "jdbc:mysql:replication//..", MySQL connector/J returns the ReplicationDriver implementation.
If you set the driver-class as com.mysql.jdbc.ReplicationDriver all your datasources are decoded as "replication url" and must always contains a master and at least one slave.
I think is better to choose the correct implementation with the url customization (replication, loadbalance, fabric...).

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">

Tomcat 7 (JBoss EWS 2.0) + MySQL 5.1 + Hibernate - OpenShift - No persistence unit found

Every time I try to reach my app on OpenShift I receive the "No Persistence provider for EntityManager named appname" error.
I have been struggling to resolve this problem for two consecutive days and I still did not find an answer.
I have tried all the possible configuration I found over the web.
My current configuration:
META-INF\persistence.xml
<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="appname" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/comp/env/jdbc/appname</jta-data-source>
<class>myorg.mypackage.MyClass</class>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory" />
</properties>
</persistence-unit>
</persistence>
.openshift\config\context.xml
<Context>
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/appname" password="mypass"
type="javax.sql.DataSource" url="jdbc:mysql://myurl:3306/appname"
username="myuser" />
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
.openshift\config\server.xml
<Host name="localhost" appBase="webapps" unpackWARs="false" autoDeploy="true">
<Context docBase="appname" path="/appname" reloadable="true" source="org.eclipse.jst.jee.server:appname" />
</Host>
The exception
javax.persistence.PersistenceException: No Persistence provider for EntityManager named appname
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at org.andvicoso.shopand.model.dao.base.GenericDaoJPA.<init>(GenericDaoJPA.java:20)
at org.andvicoso.shopand.model.dao.ProductDaoJPA.<init>(ProductDaoJPA.java:8)
at org.andvicoso.shopand.web.ViewHelper.getProductDao(ViewHelper.java:31)
at org.andvicoso.shopand.web.ViewHelper.getHighlights(ViewHelper.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:106)
at org.apache.jsp.index_jsp._jspx_meth_c_005fset_005f6(index_jsp.java:260)
Can anyone help me???
Thanks in advance.
I faced this issue and found that my META-INF was under src\main\java which was causing this error. When I moved META-INF to src\main\resources... it worked.