views:

156

answers:

4

Hello,

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. 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

+1  A: 

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.

cletus
I have looked and used ibatis. I dont see how this helps with my problem. Am i missing something?
Paul
+1  A: 

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)

Bozho
Sticking to ANSI SQL also means that you're quite limited in what you can do, as there are many things that lie outside the scope of the standard. (Especially if only older versions of the spec are supported.)
Donal Fellows
+1  A: 

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.

Nathan Voxland
A: 

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).

Pascal Thivent