Configuring Custom database in Hybris

By default,Hybris uses HSQL DB and it’s been configured in the project.properties file inside platform folder.

If we open the project.properties file inside platform folder we can find the below details

  1. #HSQL DB configuration
  2. db.url=jdbc:hsqldb:file:${HYBRIS_DATA_DIR}/hsqldb/mydb;shutdown=true;hsqldb.cache_rows=100000;hsqldb.cache_size=20000;hsqldb.write_delay_millis=1000;hsqldb.inc_backup=true;hsqldb.defrag_limit=2;hsqldb.nio_data_file=false
  3. db.driver=org.hsqldb.jdbcDriver
  4. db.username=sa
  5. db.password=
  6. db.tableprefix=
#HSQL DB configuration
db.url=jdbc:hsqldb:file:${HYBRIS_DATA_DIR}/hsqldb/mydb;shutdown=true;hsqldb.cache_rows=100000;hsqldb.cache_size=20000;hsqldb.write_delay_millis=1000;hsqldb.inc_backup=true;hsqldb.defrag_limit=2;hsqldb.nio_data_file=false
db.driver=org.hsqldb.jdbcDriver
db.username=sa
db.password=
db.tableprefix=

These properties provide the configuration details required for connecting HSQL DB.

We can add MYSQL,Oracle or SQLServer DB configuration details to configure the corresponding DB using the same keys but with respective values.

MYSQL DB configuration should have below details

  1. db.url=jdbc:mysql://localhost/<dbname>?useConfigs=maxPerformance&characterEncoding=utf8
  2. db.driver=com.mysql.jdbc.Driver
  3. db.username=<username>
  4. db.password=<password>
  5. db.tableprefix=
db.url=jdbc:mysql://localhost/<dbname>?useConfigs=maxPerformance&characterEncoding=utf8
db.driver=com.mysql.jdbc.Driver
db.username=<username>
db.password=<password>
db.tableprefix=


Oracle DB configuration should have below details

  1. db.url=jdbc:oracle:thin:@<host>:1521:<sid>
  2. db.driver=oracle.jdbc.driver.OracleDriver
  3. db.username=<username>
  4. db.password=<password>
  5. db.tableprefix=
db.url=jdbc:oracle:thin:@<host>:1521:<sid>
db.driver=oracle.jdbc.driver.OracleDriver
db.username=<username>
db.password=<password>
db.tableprefix=

We need to specify the details like DB name,driver name and credentials for the same keys accordingly.

Where do we need to define the MYSQL/Oracle DB configuration?

In platform’s project.properties file itself?
Absolutely not,We know that in Hybris we should not touch any of the existing extensions including platform extension.

But this file is available in platform extension then where to add the MYSQL/Oracle DB details?
local.properties file
Yes we should add the MYSQL/Oracle DB configuration details in the local.properties file available inside config folder

Since we are going to use the same keys with different values, the highest precedence always goes to local.properties file first and hence MYSQL DB will be connected rather than HSQL DB.
For more details on the properties file and their precedence, please read this article.

If we don’t define any DB related configuration inside local.porperties file then HSQL DB configuration inside platform’s project.properties file will be considered and HSQL DB will be connected.

Note:

Make sure that whatever the Database we configure with Hybris should be connected in the system.
So install and configure the DB in the system before accessing it from Hybris.

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on