当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Database independency using Hibernate

问题描述:

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.

网友答案:

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.

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: