Announcement Announcement Module
No announcement yet.
Handling criteria without Hibernate dependancies? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Handling criteria without Hibernate dependancies?

    I'm having a hard time wrapping my head around something. I'm sure this is easier than I think, but I'm having a major mental block.

    Let's say I have a "search" screen that allows a user to specify query criteria, like start and end date, project manager, city, state, etc. They can either leave the criteria wide open (wildcard) or specify values for a handful of fields.

    Currently my Struts actions handle this by looking at the specified values and passing them down to DAO methods which have (far too) many input parameters. These in turn build Hibernate Query or Critera objects and throw them against the database. It works fine, but the DAO method signatures are ugly. And I don't want to use the Hibernate Criteria objects above the DAO layer, because then I'd tie my service layer to a specific DAO implementation (Hibernate).

    How would you refactor this?

    Thanks in advance,

  • #2
    You can pass only an argument (e.g. the Hibernate business object) and create a criteria for those fields not null.

    That's what I do in a generic way (only a dao for all application) using Hibernate metadata.

    You can check it at in the oness-common-model module



    • #3
      That's interesting, but how would you represent value ranges using query by example (QbE) objects?


      • #4
        I don't use ranges but maybe you could pass two values and check for not null values in the second, then it would be a range.