Chanaka De Silva Chanaka De Silva - 1 year ago 66
Java Question

How to use MySQL in Spring and Hibernate background which currently uses HSQLDB

I have a project created using Spring & Hibernate. The database is used in this project is HSQLDB. ( Actually I haven't use that database earlier and no idea about it. This is the GitHub repository of the project. ( In the

file, you can see the hsql version and everything.


There are two things I need to know. I'm creating a REST API for an Accounting System using this project. Is it ok to use HSQLDB for that kind of a project? Performance and functionalities?

And also how can I use MySQL with this project? Is there any way to remove HSQL and use MYSQL insteed of? Do I need to do lot of changes if I need to change the database to MYSQL?

Answer Source

On your pom.xml add this:


then on your applicationContext.xml replace those hsqldb stuffs with these:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="packagesToScan" value="The package the contains your entities here e.g. com.example.model" />
  <property name="jpaVendorAdapter">
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
  <property name="jpaProperties">
        <prop key="">validate</prop>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  <property name="url" value="jdbc:mysql://localhost:3306/your-database-here" />
  <property name="username" value="db-username" />
  <property name="password" value="db-password" />