• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does an ORM framework exist for JAVA that generates SQL so you only ever deal with Objects?

 
Stephen Foster
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I came across a Python Web framework called Django which has an interesting way of dealing with database access. You never actually write any SQL. Instead you query objects that map to database tables. The clever bit is that where in Hibernate you'd have to write some HQL to retrieve the data from the DB. Django writes the SQL for you in the background, executes it and returns it back as an object.

I've been using Hibernate and Ibatis for a couple of years now and I was wondering if theres a java framework that closely matches this behavoir?

If there aint then I might have a go at writing one!

http://www.djangoproject.com/
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Greenhorn! Welcome to the JavaRanch!

First things first. We need to mosey on over to our JavaRanch profiles and update our name to make sure we're not makin' a mockery of ye olde JavaRanch Naming Policy.

Now, onto your question. I think you'd be impressed if you looked at the Hibernate/JPA Criteria API. It does just that - objects are used, Java APIs do things like create restriction classes and example classes, and given an example, restriction, or other type of criteria, very complex SQL is created under the covers. It's pretty awesome, and no HQL/SQL is required.

Here's a little something I wrote on the topic of the Hibernate Criteria API:

Using the Criteria API to Perform Queries

Here's an example of the code:



And another one:



Now go deal with that darn name of yours, before the Sheriffs come a wanderin!

-Cameron McKenzie
 
Stephen Foster
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply! Hibernate/JPA API looks exactily what I'm looking for. I'll check it out thanks.

p.s. Who says my name isn't Beave Beave
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick replies is what we pride ourselves on here at the ranch!

And keep asking good questions, and we'll keeps trying to help out with good answers.

And thanks for being so darned understanding about the name policy.

-Cameron McKenzie
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ORMs that eliminate (some, most) of the need for hand-written SQL, but bear in mind they might not always be appropriate, or the best solution. Hibernate is amongst the most popular/best known, but there are others.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic