Skip to content

Hibernate – passing a complete object to HQL or find()

I'm currently experimenting with Hibernate (hope I'd get back to OFBiz soon; or that OFBiz uses Hibernate sooner).

Is there a way that I can retrieve (find/load) records from the database using my an object in the following manner:
//foo and bar does not relate to the Object's primary keys
//Other properties have null or unset values
List list =   session.find(myObject);
// looks up an object in the database that matches foo (f) and bar(b)

Is there a similar thing in Hibernate that would allow to load / find an object from the database by passing a temp object filled with the required criteria into a Hibernate function?

Appreciate the help.


Found it – Thanks for the folks at Hibernate Beginner's Forum and anthony from Hibernate team:

The folks at Hibernate have done a great job. It is already there. I'll try it tomorrow.

It's called “Example Queries” (Query By Example – QBE) Pardon my ignorance – it seems that it's already widespread.

Posted in Java.

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Carlos Sanchez says

    Sure, you can use the Criteria API. An already made solution is at
    Method find(AuditableBusinessObject, int, int)

    You can just use the jar files created.

Some HTML is OK

or, reply to this post via trackback.