Robert Li
Robert Li

Reputation: 1

how can i using openshift environment variables in hibernate.cfg.xml

I am using Hibernate on OpenShift now.

In hibernate.cfg.xml

When I use:

<property name="connection.url">jdbc:mysql://10.143.140.62:52016/yoodp</property>

It works.

But when I use:

<property name="connection.url">jdbc:mysql://${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/${env‌​.OPENSHIFT_APP_NAME}</property>

or

<property name="connection.url">jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}</property>

It doesn't work.

How can I fix it?

Upvotes: 0

Views: 1072

Answers (2)

MartinB
MartinB

Reputation: 231

I'm guessing you're using Openshift Tomcat, so to connect to your MySQL database simply use the datasource that is already defined for you.

The JNDI datasource is named jdbc/MySQLDS and you use it in hibernate with the connection.datasource property.

https://help.openshift.com/hc/en-us/articles/202399720-How-to-use-the-pre-configured-MySQLDS-and-PostgreSQLDS-data-sources-in-the-Java-cartridges

Upvotes: 2

Shafin Mahmud
Shafin Mahmud

Reputation: 4071

${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.

Upvotes: 0

Related Questions