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
- #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=
#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
- db.url=jdbc:mysql://localhost/<dbname>?useConfigs=maxPerformance&characterEncoding=utf8
- db.driver=com.mysql.jdbc.Driver
- db.username=<username>
- db.password=<password>
- 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
- db.url=jdbc:oracle:thin:@<host>:1521:<sid>
- db.driver=oracle.jdbc.driver.OracleDriver
- db.username=<username>
- db.password=<password>
- 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.
Ps: Just MySql server 5.6 or 5.7 are supported by Hybris with Jdbc connector 5.1
To do : You should add Jdbc connector 5.1 to \bin\platform\lib\dbdriver
Hello ,
please i am creating a new project with hybris and i want to create a tables in my DB how can i do that ?