This blog for Hibernate Generic DAO Project has been moved to WordPress Bye bye Blogger!

Thursday, March 11, 2010

Version 0.5.1 Released with a number of bug fixes

Tonight I pushed a new build (0.5.1) to the Maven repository. This has been a long time in coming, and consists primarily of bug fixes. (For a list of all issues fixed in this release see the Road Map).

There is one important change in the Generic DAO interface, however. We changed the signature of the search() and searchUnique() methods.

Old Signature:

List<ENTITY_CLASS> search(Search search);
ENTITY_CLASS searchUnique(Search search);

New Signature:

<EXPECTED_TYPE> List<EXPECTED_TYPE> search(Search search);
<EXPECTED_TYPE> EXPECTED_TYPE searchUnique(Search search);

The old signature assumed that every search would return the root entity type, but with the Fields and result mode options on the Search, this is not always so. The old solution for this was to have two additional methods: searchGeneric and searchUniqueGeneric which returned List<?> and Object types respectively. The new approach eliminates the need for these confusing methods.

If you are unfamiliar with this sort of generic method signature, what it does is determine the return type of the method based on the context from which it is called, effectively reducing the need for explicit casting. (Here's a more in-depth description.)

For example, if we're using the RESULT_ARRAY result mode...

Old way:

List<Object[]> results = (List<Object[]>) dao.searchGeneric(search);

New way:

List<Object[]> results =;

With the new method signatures, the Java compiler is able to infer from the type of the "results" variable that search() will return a list of type List<Object[]>. There is no longer a need to explicitly cast it in most cases.

In addition to all this, we added a new (Beta) implementation of MetadataUtil that uses JPA Annotations to determine the persistence meta model. The implication of this is that the framework should be able to be used, out of the box, with other JPA providers like OpenJPA, TopLink, etc. I hope to post more on just how to configure this when I have time.


  1. Regards David
    Congratulations on your work.
    Please could you help me with the configuration of GENERIC JAVA DAO for platform Spring + EclipseLink + JPA
    Jorge Vallejo

  2. Regards David
    This is a posible configuration for GENERIC JAVA DAO + JPA...?
    Any sugestion..?

  3. Okay. So you made me finally fulfill my promised post on configuring with JPA.

  4. Dave-
    Can you please restore the link for ProjectDAO example?

  5. I didn't find the link you are referring to. Can you give me a more specific description of where this link is that needs to be fixed?

  6. here you go..

  7. The link is fixed:

  8. Regards,
    congrats also from here.

    This seems the absolutely right thing for my new project...

    Will try within the next weeks.

    Thanks a lot for contributing!

  9. David,

    Thanks a lot for a generic framework! I am going to use it for my new project.


  10. Awesome project...saved me a lot of time (using Flex & Spring & Hibernate), well I wrote my own and I had several test projects trying to get RDS to work without coming across overloaded methods Introspection errors, question is how does the FlexDAOAdapter come into action? An example would help thanks...

  11. Amazing & Great informative blog,it gives very useful practical information to developer like me. Besides that Wisen has established as Best Hibernate Training in Chennai .