1

I am using Hibernate for ORM in my Java application. I want to write custom queries combining multiple tables and using DB functions like sum(salary). I also want to support multiple databases without writing the SQLs again and again for each database. The approach currently followed is having Stored Procedures specific to each DB (Oracle, MySQL etc) and whichever we want to support, we change the configuration file in the application. What I am looking for is a solution very generic so that I need not write Stored Procedures or SQLs for every new functionality.

2 Answers 2

1

If you really want to keep it portable, you'll need to do it all with HQL.

There's no reason that you couldn't do multi-table joins and aggregate functions in HQL, you just need to limit yourself to the ones it supports.

Once you start doing database-vendor specific things, you are no longer database independent, by definition.

Sign up to request clarification or add additional context in comments.

Comments

1

A perfect suite is HIbernate Criterias

Hibernate provides alternate ways of manipulating objects and in turn data available in RDBMS tables. One of the methods is Criteria API which allows you to build up a criteria query object programmatically where you can apply filtration rules and logical conditions.

http://www.tutorialspoint.com/hibernate/hibernate_criteria_queries.htm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.