views:

64

answers:

2

We are using Eclipselink for ORM, but we have a need for some more lightweight database interactions that are more equivalent to JDBC. My question is whether Eclipselink supports such an idiom and whether there are any advantages of it to straight JDBC. I can see one advantage being consistency and being able to use the existing connection handling. Others?

Specifically, what I'm looking for is something equivalent to Hibernate's Native SQL Query.

+1  A: 

EclipseLink implements JPA - you can run SQL queries via an EntityManager. If you start running SQL queries not related to the model of your application you'll have no advantages over JDBC - on the contrary you'll be using a much heavier infrastructure. If you tie the SQL to the model however you'll have the advantage of making additional optimizations to queries utilizing the full db potential. I'm not sure if that's what you want to do however...

Bozhidar Batsov
+1  A: 

If you are using both JPQL and SQL queries in your application then JPA 2 native queries are probably the right approach. Here are some examples :

http://www.oracle.com/technology/pub/articles/vasiliev-jpql.html

If your app only uses SQL queries and updates, then ORM is just an overhead. You can get declarative transactions also differently, for example via Spring's JDBC support.

Timo Westkämper
But looking at it, it appears that using a native query only means that I'm using SQL instead of JPQL. I'm still tied to the/an object model as far as I can see or a single scalar result. If I just want to get a row out of the database, do I necessarily have to create a Class to map to the result?
Tim
I believe for more flexible result set mapping you should consider using Spring JDBC support.
Timo Westkämper