Spring Hibernate Sybase Integration example

Spring Hibernate Sybase Integration example

Building application from scratch is one of the biggest task in software development and if you got requirement to build application using Spring Hibernate and Sybase database hmmm… challenging but I will make your life little easy to give you some idea about how to get going with this kind of architecture. I will be building application using yes Spring Hibernate and Sybase database and will show how to use @Transactional annotation and handle transaction and in this example we just call and get data using store procedure, native select query and hibernate ORM. Let’s get started:

  • First create table using below script in Sybase database I using version¬†Adaptive Server Enterprise 15.7.:

  • Also create store procedure which will make call to above table to get the data and for our example we will call both table and store procedure to get data:

  • Insert some dummy data for test:

  • Create maven project name: SpringHibernateSysbaseIntegration below is final project structure:


  • As you see above I have created separate package for dao, model and application test also kept all properties files in src/main/resources folder and database, queries and context in src/main/config folder separately. As nothing much to explain about it I will give explanation in the file what I am doing:

Spring Hibernate Sybase Integration example

  • pom.xml: Managing project dependencies:

  • hibernate.properties: This file we are putting all database related information like url, user name, password and hibernate related configuration:

  • application.properties: This is where we will keep application related properties mapping.

  • log4j2.xml: For keeping log of the application:

  • hibernate-context.xml: Hibernate related configuration where you need to configure datasource, session factory etc…

  • hibernate.queries.xml: Here you can defined hibernate queries:

  • spring-context.xml: Heart of the application where initialization starts for Spring framework and here you mentioned and include all your beans, configuration etc…

  • EquitySwapTestModel.java: This is hibernate model class for the table which create into the database:

  • EquitySwapTestModelForProcedure.java: I have create another model class for to populate all data when calling the store procedure. Please pay attention on the attribute name: rowKey actually its dummy key which will be unique all time when you get data through store procedure.

  • GenericDao.java: Interface for all methods definition which we will use for our testing:

  • GenericDaoHandler.java: Main implementation class where we are making call to the database. I think you will need to pay extra attention to this class because if you are creating your application just you need to find how you can make different type to call to the database:

  • HibernateTestApp.java: Main test class to test this application:

  • That’s it. To run this application right click HibernateTestApp.java and Run As java application and if everything setup correctly you should get all data as below:

Spring Hibernate Sybase Integration example

  • For more information please visit spring documentation here

download Download Project: SpringHibernateSysbaseIntegration

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *