PDA

View Full Version : Handling criteria without Hibernate dependancies?


smccrory
Aug 22nd, 2004, 09:51 PM
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,
Scott

carlos
Aug 23rd, 2004, 06:36 AM
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 http://oness.sourceforge.net in the oness-common-model module

Regards

smccrory
Aug 23rd, 2004, 01:24 PM
That's interesting, but how would you represent value ranges using query by example (QbE) objects?

carlos
Aug 23rd, 2004, 01:40 PM
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.