sumit badaya sumit badaya - 3 months ago 34
MySQL Question

How to set Hibernate MySQL Connection in Openshift Tomcat 7 (JBOSS EWS 2.0)?

I'm developing Java based web application using spring hibernate and am trying out OpenShift to deploy my application. But I am facing troubles in configuring my application for the MySQL connector. I have included mysql-connector in my Maven dependency.

Below is my maven's

pom.xml
file's mysql dependency code:

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>


And here is my servlet-xml code:

<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/jbossews" />
<beans:property name="username" value="${OPENSHIFT_MYSQL_DB_USERNAME}" />
<beans:property name="password" value="${OPENSHIFT_MYSQL_DB_PASSWORD}" />
</beans:bean>


But when I deploy this to my openshift account and hit the address of my controller, it shows the below error:


HTTP Status 500 - Request processing failed; nested exception is
org.springframework.transaction.CannotCreateTransactionException:
Could not open Hibernate Session for transaction; nested exception is
org.hibernate.exception.GenericJDBCException: Could not open
connection


I must be misconfiguring my MySQL stuff in xml file.

Answer

I got an answer:

${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/${env‌​.OPENSHIFT_APP_NAME}

these are the OpesnShift variables. you cant use them for configuration. They should be replaced by their real values which you have done for the first one.