Fully Distributed Hadoop Cluster - Automatic Failover HA Cluster with Zookeeper & QJM - hadoop2

I have set up my Fully Distributed Hadoop Cluster - Automatic Failover HA Cluster with Zookeeper & QJM by folowing the below link.
http://hashprompt.blogspot.in/2015/01/fully-distributed-hadoop-cluster.html
hduser#ha-nn01:/opt/zookeeper-3.4.7/bin$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
hduser#ha-nn01:/opt/zookeeper-3.4.7/bin$ jps
2919 Jps
2895 QuorumPeerMain
Everything is fine up to now. When I type the below command:
hduser#ha-nn01:/opt/hadoop-2.6.0$ bin/hdfs zkfc –formatZK
I got the below error message and I don't how to resolve this.
Error:
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:os.arch=i386
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:os.version=3.13.0-24-generic
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:user.name=hduser
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/hduser
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Client environment:user.dir=/opt/hadoop-2.6.0
15/12/09 04:31:07 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=ha-nn01:2181,ha-nn02:2181,ha-nn03:2181 sessionTimeout=5000 watcher=org.apache.hadoop.ha.ActiveStandbyElector$WatcherWithClientRef#deea7f
15/12/09 04:31:07 INFO zookeeper.ClientCnxn: Opening socket connection to server ha-nn01/192.168.71.138:2181. Will not attempt to authenticate using SASL (unknown error)
15/12/09 04:31:07 INFO zookeeper.ClientCnxn: Socket connection established to ha-nn01/192.168.71.138:2181, initiating session
15/12/09 04:31:08 INFO zookeeper.ClientCnxn: Session establishment complete on server ha-nn01/192.168.71.138:2181, sessionid = 0x1518612d0000000, negotiated timeout = 5000
Usage: java zkfc [ -formatZK [-force] [-nonInteractive] ]
15/12/09 04:31:08 INFO ha.ActiveStandbyElector: Session connected.
15/12/09 04:31:08 INFO zookeeper.ZooKeeper: Session: 0x1518612d0000000 closed
Exception in thread "main" org.apache.hadoop.HadoopIllegalArgumentException: Bad argument: –formatZK
at org.apache.hadoop.ha.ZKFailoverController.badArg(ZKFailoverController.java:249)
at org.apache.hadoop.ha.ZKFailoverController.doRun(ZKFailoverController.java:212)
at org.apache.hadoop.ha.ZKFailoverController.access$000(ZKFailoverController.java:61)
at org.apache.hadoop.ha.ZKFailoverController$1.run(ZKFailoverController.java:170)
at org.apache.hadoop.ha.ZKFailoverController$1.run(ZKFailoverController.java:166)
at org.apache.hadoop.security.SecurityUtil.doAsLoginUserOrFatal(SecurityUtil.java:412)
at org.apache.hadoop.ha.ZKFailoverController.run(ZKFailoverController.java:166)
at org.apache.hadoop.hdfs.tools.DFSZKFailoverController.main(DFSZKFailoverController.java:180)
15/12/09 04:31:08 INFO zookeeper.ClientCnxn: EventThread shut down
Set up:
192.168.71.138 ha-nn01
192.168.71.139 ha-nn02
192.168.71.140 ha-nn03
192.168.71.141 ha-dn01
192.168.71.142 ha-dn02
192.168.71.143 ha-dn03
192.168.71.144 ha-client
Note:
HDFS-SITE.XML File Configuration:
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.name.dir</name>
<value>file:///hdfs/name</value>
</property>
<property>
<name>dfs.data.dir</name>
<value>file:///hdfs/data</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
<property>
<name>dfs.nameservices</name>
<value>auto-ha</value>
</property>
<property>
<name>dfs.ha.namenodes.auto-ha</name>
<value>nn01,nn02</value>
</property>
<property>
<name>dfs.namenode.rpc-address.auto-ha.nn01</name>
<value>ha-nn01:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.auto-ha.nn01</name>
<value>ha-nn01:50070</value>
</property>
<property>
<name>dfs.namenode.rpc-address.auto-ha.nn02</name>
<value>ha-nn02:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.auto-ha.nn02</name>
<value>ha-nn02:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://ha-nn01:8485;ha-nn02:8485;ha-nn03:8485/auto-ha</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/hdfs/journalnode</value>
</property>
<property>
<name>dfs.ha.fencing.methods</name>
<value>sshfence</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/hduser/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled.auto-ha</name>
<value>true</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>ha-nn01.hadoop.lab:2181,ha-nn02.hadoop.lab:2181,ha-nn03.hadoop.lab:2181</value>
</property>

If you copy the command "hdfs zkfc -formatZK" from the microsoft word, sometimes the '-' is longer than the real, so in the terminal don't understand this line.

Related

EJB/Hibernate does not access MySQL Database

I'm trying to learn how to work with JavaEE/EJB and database persistence, I have a basic example where I want to save a String to a database via input field and read the list of saved items.
I have a MySQL server installed on localhost (V5.7 Community Edition) and my test server is WildFly 10.1.0 (via Eclipse). The whole project is an EAR container containing a Web and EJB Subproject.
I am using container managed transactions, as I understand it, transactions are automatically created when a method is called and flushed/committed as soon as the method exits.
The problem is, that no data is ever written to the actual database. But no errors are thrown either. I assume, the entity manager caches all supposed saves and directly reads them back on select, without even checking the database. As such, when I restart the server, nothing remains. Also, when I look into mysql db directly, nothing is there either (even while wildfly server is running, directly after supposed insert). I also tried adding some rows to db table directly, but select does not "see" them either.
As a result, it seemed to me that the database is not even accessed, despite it being configured in the persistence.xml. I tried to remove connection url/username/password there and it actually made no difference, the entity manager still throws no errors and everything seems to work. So where exactly is it saving the data and what do I have to change so that it accesses the supplied mysql database instead?
Handler (in Web Project):
#ManagedBean(name = "handlerBean")
#SessionScoped
public class HandlerBean {
#EJB
private TodoWorkerBeanRemote worker;
private String input;
public void add() {
if (input.compareTo("") != 0) {
TodoBean item = new TodoBean();
item.setText(input);
worker.saveItem(item);
input = "";
}
}
...
Session Bean / Transaction container (in EJB project)
#Stateless
#TransactionManagement(TransactionManagementType.CONTAINER)
public class TodoWorkerBean implements TodoWorkerBeanRemote {
#PersistenceContext(unitName = "EnterpriseTestEJB")
private EntityManager entityManager;
public TodoWorkerBean() {
}
#Override
#TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) // does not help
public void saveItem(TodoBean item) {
// entityManager.joinTransaction(); <- does not help
entityManager.persist(item); // tried .merge() as well
// entityManager.flush(); <-does not help
}
...
Entity Bean (in EJB project)
#Entity
#Table(name = "todobean")
#NamedNativeQueries({
#NamedNativeQuery(name = "TodoBean.getItems", query = "select * from todobean", resultClass = TodoBean.class),
#NamedNativeQuery(name = "TodoBean.clearItems", query = "delete from todobean") })
public class TodoBean implements Serializable {
private Integer id;
private String text;
...
persistence.xml (tried with hibernate.cfg.xml as well, no difference)
<?xml version="1.0" encoding="UTF-8"?>
<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="EnterpriseTestEJB">
<class>de.dianasalsa.ejb.TodoBean</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/feedback" /> // not used
<property name="hibernate.connection.username" value="root" /> // not used
<property name="hibernate.connection.password" value="root" /> // not used
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.hbm2ddl.auto" value="update" /> // tried "create" as well
</properties>
</persistence-unit>
</persistence>
Log:
....
15:42:59,602 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 66) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'EnterpriseTest.ear/EnterpriseTestEJB.jar#EnterpriseTestEJB'
15:42:59,952 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 65) WFLYCLINF0002: Started client-mappings cache from ejb container
15:42:59,973 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 66) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
15:43:00,102 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 66) Envers integration enabled? : true
15:43:00,101 INFO [org.jboss.as.protocol] (management I/O-1) WFLYPRT0057: cancelled task by interrupting thread Thread[management-handler-thread - 3,5,management-handler-thread]
15:43:00,604 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 66) HHH000228: Running hbm2ddl schema update
15:43:00,617 INFO [org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl] (ServerService Thread Pool -- 66) HHH000262: Table not found: todobean
15:43:00,619 INFO [org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl] (ServerService Thread Pool -- 66) HHH000262: Table not found: todobean
15:43:01,499 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 83) Mojarra 2.2.13.SP1 20160303-1204 für Kontext '/EnterpriseTestWeb' wird initialisiert.
15:43:02,379 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 83) WFLYUT0021: Registered web context: /EnterpriseTestWeb
15:43:02,414 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "EnterpriseTest.ear" (runtime-name : "EnterpriseTest.ear")
15:43:02,515 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
15:43:02,519 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
15:43:02,519 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 9581ms - Started 879 of 1127 services (422 services are lazy, passive or on-demand)
15:43:18,799 INFO [org.jboss.ejb.client] (default task-2) JBoss EJB Client version 2.1.4.Final
15:43:32,763 INFO [stdout] (default task-3) Hibernate:
15:43:32,763 INFO [stdout] (default task-3) /* insert de.dianasalsa.ejb.TodoBean
15:43:32,763 INFO [stdout] (default task-3) */ insert
15:43:32,763 INFO [stdout] (default task-3) into
15:43:32,763 INFO [stdout] (default task-3) todobean
15:43:32,763 INFO [stdout] (default task-3) (text)
15:43:32,763 INFO [stdout] (default task-3) values
15:43:32,764 INFO [stdout] (default task-3) (?)
15:43:32,786 INFO [stdout] (default task-3) Hibernate:
15:43:32,786 INFO [stdout] (default task-3) /* TodoBean.getItems */ select
15:43:32,786 INFO [stdout] (default task-3) *
15:43:32,787 INFO [stdout] (default task-3) from
15:43:32,787 INFO [stdout] (default task-3) todobean
sorry for my english...
you need to configure a JNDI name "jta-data-source", and say with "hibernate.hbm2ddl.auto" create new relations, like this example:
<?xml version="1.0" encoding="UTF-8"?>
<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="EnterpriseTestEJB"
transaction-type="JTA">
<jta-data-source>java:jboss/datasources/some-name</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
wildfly has a "namesever" for that you work with the JNDI name to access from your annotation like "#PersistenceContext".
And in Wildfly at selfe you must configure a new MySql connection with that JNDI name.
For MySql connection download the jdbc driver and upload it to WildFly.
https://dev.mysql.com/downloads/connector/j/5.1.html
Inser MySqgl jdbc Driver
The connection will named with the JNDI name (java:jboss/datasources/some-name).
Add new MySql Connection (1)
Add new MySql Connection (2)
When you run your programm in Wildfly the programm will look over the JNDI name in wildfly for your MySql connection.
If you would like to look an example code i have one from my study here:
https://gitlab.com/Java_Project/JavaEE2.0
I'll hope it fixe your problem.

MySQL + WildFly 10.0 - One or more services were unable to start

I'm trying to connect with database while deploying, but I got some trouble with that, here is a code and stacktrace:
02:19:32,740 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 45) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.mysql]"
02:19:32,814 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path 'C:\Users \Damian\wildfly-10.0.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
02:19:32,839 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0012: Started server default-server.
02:19:32,840 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0018: Host default-host starting
02:19:32,925 INFO [org.jboss.as.ejb3] (MSC service thread 1-5) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing.
02:19:32,925 INFO [org.jboss.as.ejb3] (MSC service thread 1-2) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host.
02:19:33,157 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "FiranyCRM.war" (runtime-name: "FiranyCRM.war")
02:19:33,171 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "mysql-connector-java-5.1.37.jar" (runtime-name: "mysql-connector-java-5.1.37.jar")
02:19:33,186 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) WFLYDS0013: Started FileSystemDeploymentService for directory C:\Users\Damian\wildfly-10.0.0.Final\standalone\deployments
02:19:33,232 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-6) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
02:19:33,506 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
02:19:33,771 INFO [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBossWS 5.1.3.Final (Apache CXF 3.1.4)
02:19:33,827 INFO [org.jboss.as.jpa] (MSC service thread 1-8) WFLYJPA0002: Read persistence.xml for firanyDS
02:19:33,880 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
02:19:33,882 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
02:19:33,916 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.37.jar_com.mysql.jdbc.Driver_5_1
02:19:33,917 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.37.jar_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1
02:19:34,213 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "FiranyCRM.war")]) - failure description: {
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.persistenceunit.\"FiranyCRM.war#firanyDS\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jdbc.firanyDS]",
"jboss.persistenceunit.\"FiranyCRM.war#firanyDS\" is missing [jboss.naming.context.java.jdbc.firanyDS]"
],
"WFLYCTL0288: One or more services were unable to start due to one or more indirect dependencies not being available." => {
"Services that were unable to start:" => [
"jboss.deployment.unit.\"FiranyCRM.war\".component.\"com.sun.faces.config.ConfigureListener\".START",
"jboss.deployment.unit.\"FiranyCRM.war\".component.\"javax.faces.webapp.FacesServlet\".START",
"jboss.deployment.unit.\"FiranyCRM.war\".component.\"javax.faces.webapp.FacetTag\".START",
"jboss.deployment.unit.\"FiranyCRM.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START",
"jboss.deployment.unit.\"FiranyCRM.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START",
"jboss.deployment.unit.\"FiranyCRM.war\".component.\"managed-bean.com.firanycrm.controller.CurtainBean\".START",
"jboss.deployment.unit.\"FiranyCRM.war\".component.\"managed-bean.com.firanycrm.controller.LoginBean\".START",
"jboss.deployment.unit.\"FiranyCRM.war\".deploymentCompleteService",
"jboss.deployment.unit.\"FiranyCRM.war\".jndiDependencyService",
"jboss.naming.context.java.module.FiranyCRM.FiranyCRM.DefaultDataSource",
"jboss.undertow.deployment.default-server.default-host./FiranyCRM",
"jboss.undertow.deployment.default-server.default-host./FiranyCRM.UndertowDeploymentInfoService"
],
"Services that may be the cause:" => [
"jboss.jdbc-driver.mysql",
"jboss.naming.context.java.jdbc.firanyDS"
]
}
}
02:19:34,214 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "firanyDS")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.firanyDS is missing [jboss.jdbc-driver.mysql]",
"jboss.driver-demander.java:jboss/datasources/firanyDS is missing [jboss.jdbc-driver.mysql]"
]}
02:19:34,216 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "firanyDS")
]) - failure description: {
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.firanyDS is missing [jboss.jdbc- driver.mysql]",
"jboss.driver-demander.java:jboss/datasources/firanyDS is missing [jboss.jdbc-driver.mysql]",
"org.wildfly.data-source.firanyDS is missing [jboss.jdbc- driver.mysql]"
],
"WFLYCTL0288: One or more services were unable to start due to one or more indirect dependencies not being available." => {
"Services that were unable to start:" => [
"jboss.data-source.reference-factory.firanyDS",
"jboss.naming.context.java.jboss.datasources.firanyDS"
],
"Services that may be the cause:" => [
"jboss.jdbc-driver.mysql",
"jboss.naming.context.java.jdbc.firanyDS"
]
}
}
standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:4.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/firanyDS" pool-name="firanyDS">
<connection-url>jdbc:mysql://127.0.0.1:3307/firanycrm</connection-url>
<driver>mysql</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="org.mysql">
<xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
module.xml (in modules folder, modules/org/mysql) :
<module xmlns="urn:jboss:module:1.0" name="org.mysql.driver">
<resources>
<resource-root path="mysql-connector-java-5.1.37.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.0">
<persistence-unit name="firanyDS" transaction-type="RESOURCE_LOCAL">
<jta-data-source>java:/jdbc/firanyDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</properties>
</persistence-unit>
</persistence>
In which place I made a mistake?
You have at least two problems:
In the standalone.xml, under the datasources subsystem, you set the driver module to "org.mysql" but the module name in the module.xml is "org.mysql.driver".
The jta-data-source element in persistence.xml should be the jndi name of your datasource: java:jboss/datasources/firanyDS. Besides, since you are using JTA, the transaction-type must be "JTA".
<persistence ...>
<persistence-unit name="firanyDS" transaction-type="JTA">
<jta-data-source>java:/jdbc/firanyDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</properties>
</persistence-unit>
</persistence>

Connect JBoss 5.1 MDB EJB3 to Remote JMS Provider Queue

I'm having problems with my MDB running in JBoss 5.1.2 connecting to a remote standalone HornetQ via JMS. I know the HornetQ is up and running fine as I can connect to it and place/view messages via HermesJMS. However, my actual app does not seem to be able to successfully connect to it.
Here's my #MessageDriven annotation:
#MessageDriven(
messageListenerInterface = MessageListener.class,
activationConfig = {
#ActivationConfigProperty( //type of destination we pull messages from
propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
#ActivationConfigProperty( //which destination JNDI suffix we pull message from
propertyName = "destination", propertyValue = "queue/inputQueue"),
#ActivationConfigProperty( //how many times to reattempt on service errors
propertyName = "dLQMaxResent", propertyValue = "1"),
#ActivationConfigProperty( //how many seconds to try a reconnect when failure to connect to jms provider
propertyName = "reconnectInterval", propertyValue = "15"),
#ActivationConfigProperty(
propertyName = "providerAdapterJNDI", propertyValue = "java:/RemoteJMSProvider")
}
)
Here's my configuration in my jms-ds.xml file:
<mbean code="org.jboss.jms.jndi.JMSProviderLoader"
name="hornetq:service=MSProviderLoader,name=RemoteJMSProvider,server=remotehost">
<attribute name="ProviderName">RemoteJMSProvider</attribute>
<attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
<!-- The connection factory -->
<attribute name="FactoryRef">/LocalHornetQConnectionFactory</attribute>
<!-- The queue connection factory -->
<attribute name="QueueFactoryRef">/LocalHornetQConnectionFactory</attribute>
<!-- The topic factory -->
<attribute name="TopicFactoryRef">/LocalHornetQConnectionFactory</attribute>
<!-- Connect to JNDI on the host "the-remote-host-name" port 1099-->
<attribute name="Properties">
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=IPADDRESS:1099
</attribute> </mbean>
I can view the RemoteJMSProvider in the JBoss jmx-console. Additionally, in JNDIView, I can see the JNDI name of the Remote JMS Provider. I can also see the jms.queue.inputQueue in the JMX console, though when I attempt to view messages on it, it says there are none, even though I know there are by viewing HermesJMS.
Finally, there are no exceptions in my application. It all appears to be running fine, but it never receives any messages. Even the HornetQ logs show that my IP address has connected, so I'm not sure why I can't read off of the queues:
[RMI TCP Connection(6)-10.3.78.123] 17:02:06,837 FINER [sun.rmi.transport.tcp] RMI TCP Connection(6)-10.3.78.123: (port 1098) client using 10.3.78.123:0
Any ideas?
Here's my HornetQ (2.2.5) configuration information for reference.
hornetq-jms.xml:
<connection-factory name="LocalHornetQConnectionFactory">
<xa>true</xa>
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="/LocalHornetQConnectionFactory"/>
</entries>
<retry-interval>5000</retry-interval>
<retry-interval-multiplier>1.0</retry-interval-multiplier>
<reconnect-attempts>-1</reconnect-attempts>
<failover-on-server-shutdown>true</failover-on-server-shutdown>
<confirmation-window-size>1048576</confirmation-window-size>
</connection-factory>
<queue name="invalidQueue">
<entry name="/queue/invalidQueue"/>
</queue>
<queue name="inputQueue">
<entry name="/queue/inputQueue"/>
</queue>
<queue name="errorQueue">
<entry name="/queue/errorQueue"/>
</queue>
<topic name="SAFEStorageAcknowledgement">
<entry name="/topic/SAFEStorageAcknowledgement"/>
</topic>
<topic name="SAFEEvents">
<entry name="/topic/SAFEEvents"/>
</topic>
hornetq-configuration.xml:
<address-settings>
<!--default for catch all-->
<address-setting match="#">
<dead-letter-address>jms.queue.errorQueue</dead-letter-address>
<expiry-address>jms.queue.errorQueue</expiry-address>
<redelivery-delay>15000</redelivery-delay>
<max-size-bytes>10485760</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>BLOCK</address-full-policy>
<redistribution-delay>60000</redistribution-delay>
</address-setting>
</address-settings>
<queues>
<queue name="jms.queue.inputQueue">
<address>jms.queue.inputQueue</address>
</queue>
<queue name="jms.queue.errorQueue">
<address>jms.queue.errorQueue</address>
</queue>
<queue name="jms.queue.invalidQueue">
<address>jms.queue.invalidQueue</address>
</queue>
</queues>
All other HornetQ settings are at default.
Thanks,
Andy
You have to specify on either the ra.xml or as an annotation two activation properties:
ConnectorClassName = org.hornetq.core.remoting.impl.netty.NettyConnectorFactory
ConnectionParameters = host=127.0.0.1;port=5446
On the HornetQ distribution, there's an example called javaee/jca-remote which is using the ra.xml to configure the activation property.

Having connection issue Hibernate 3.0 with MySQL

I am getting this error. I have my hibernate connections and MVC all setup correct I believe.
I heard MySQL drivers have an issue for database connection.
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/AdministrativeApplication] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection] with root cause
java.sql.SQLException: Unknown database 'testDB'
My hibernate configuration file
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<!-- Load Hibernate related configuration -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/testDB" />
<property name="username" value="myroot"/>
<property name="password" value="*****"/>
<!-- connection pooling details -->
<property name="initialSize" value="1"/>
<property name="maxActive" value="5"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<!-- Declare a transaction manager-->
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<!-- all the annotation entity classes -->
</list>
</property>
</bean>
<!-- Declare a transaction manager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
</beans>
Please let me know what
I could do to resolve this error.
I further added a new java file to test
import java.sql.*;
public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "root";
String password = "******";
String url = "jdbc:mysql://localhost:3306/testDB";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
e.printStackTrace(System.out);
System.err.println ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
I get this error . Also I started the MySQL console with this command.
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld.exe"
I get this error
java.sql.SQLException: Unknown database 'testdb'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:798)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3700)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1203)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2572)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Connect.main(Connect.java:15)
Cannot connect to database server
Can some please help resolve this.
i ran netstats no luck. I do not see at what port MySQL is listening at.
Thanks again .
Dhiren
I am getting this error.
This means you did something wrong.
I have my hibernate connections and MVC all setup correct I believe.
See my previous comment - you did not do everything correctly.
I heard MySQL drivers have an issue for database connection.
Nope - MySQL drivers work fine if you set them up properly. You're doing something wrong, and you'll make progress faster if you take that attitude.
Before you run Java, start up the MySQL client, log into MySQL. If you can't, Java won't be able to, either. See if the daemon is up and running.
See if you have that database available. If not, create it.
If it is created, make sure that you have the tables you need and the user you're logging in as has appropriate permissions.
You could create a database named "testDB" in your MySQL instance.

JPA + MySQL: After Timeout --> use a local Connection

as our connection is very unstable we have decided to switch to our local read-only database if a query times out.
But here is my problem: I do not get an exception when javax.persistence tries to query:
// Attribute
EntityManagerFactory entityManagerFactory;
EntityManager manager;
entityManagerFactory = Persistence
.createEntityManagerFactory("org.hibernate.tutorial.jpa");
manager = entityManagerFactory.createEntityManager();
try {
Query query = manager.createQuery(String.format(
"SELECT u FROM User u WHERE u.id = '%s'", 116));
User user = (User) query.getSingleResult();
manager.refresh(user);
System.out.println(user.getUsername());
} catch (org.hibernate.QueryTimeoutException ex) {
throw new QueryTimeoutException("timeout");
}
}
This is just a test to demonstrate my problem.
What am I missing?
Mysql: mysql-connector-java-5.1.16-bin.jar
JPA: javax.persistence_2.0.3.v201010191057.jar
Hibernate:
115 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
124 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.7.Final
126 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
129 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
132 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
208 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.6.7.Final
persistence.xml:
<properties>
<property name="hibernate.hbm2ddl.auto" value="valide"/>
<property name="hibernate.connection.url" value="jdbc:mysql:///database?zeroDateTimeBehavior=convertToNull"/>
<property name="hibernate.connection.username" value="user"/>
<property name="hibernate.connection.password" value="pass"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.query.timeout" value="1"/>
<property name="dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
Thank you
Tobias
Solution:
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://server/database", "user", "pass");
Every time I want to start a query I test if the Connection is alive:
if (connection.isValid(1)) {
return true;
} else {
throw new NoConnectionException();
You may not be seeing a timeout because some DBs don't support that feature.
"javax.persistence.query.timeout query timeout in milliseconds
(Integer or String), this is a hint used by Hibernate but requires
support by your underlying database."
See http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/configuration.html for more details.
I'd be inclined to switch to the read only all the time if you can't guarantee a reliable connection.