开发者

Java SQL database independence

开发者 https://www.devze.com 2022-12-25 05:44 出处:网络
I have been looking for an alternative to Hibernate for various reasons. I came across Liquibase and i like the idea so i am willing to try it开发者_C百科. Liquibase will cater for database creation/m

I have been looking for an alternative to Hibernate for various reasons. I came across Liquibase and i like the idea so i am willing to try it开发者_C百科. Liquibase will cater for database creation/modification in a SQL independent fashion. My main question is how does my code in my application execute SQL statements without being database dependent? Is there some other project that acts like Hibernates Dialect classes?

Thanks,

Paul


My main question is how does my code in my application execute SQL statements without being database dependent?

Well, the only way to really achieve this is to use a higher level query language than SQL that would be translated into database specific SQL. And we have already a few (proprietary, standard) DSLs for this: Toplink QL, EJB-QL, JDO QL, HQL, JPQL, etc. My suggestion would be to pick your poison (but please, don't roll your own solution).


One of the issues with using SQL is that it is vendor-dependent. I don't think there's any way of getting around that without using some third-party library or framework (like Hibernate!).

But if you do go with SQL, I'd strongly recommend you take a look at Ibatis.


I doubt it - the dialects in hibernate are used for translating objects and HQL queries to proper native queries.

If you want to use plain SQL queries, then you should translate SQL queries to.. SQL queries.

One way to achieve database independence is to use only ANSI SQL. But even that does not guarantee complete database independence.

I'd suggest sticking with hibernate and HQL (JPA-QL)


If you want to use liquibase's SQL generation classes outside of the normal liquibase process you can. Especially in 2.0, the sql generation classes have been improved and abstracted, but depending on what you are wanting to run, it may not meet your needs.

Since liquibase is about database migrations, most of the database-independent logic is around DDL statements (create table/add column etc.) and not as much around insert/update/delete statements. Not knowing what type of statements you will run, I would assume you are more concerned about cross-database insert/update/delete statements in which case you will be better served by hibernate/ibatis/etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消