I know that having domain objects for business layer and presentation/search/criteria object for presentation layer is a text book approach. For example, I could have domain class Customer and then another class CustomerSerachCriteria that presentation layer would pass to business layer whenever a search needs to be performed. The problem is that I would have to have some kind of mapping between two classes which is an extra coding I don't want to do.
Let's say I don't care about a clean separation between domain and presentation objects. Let my presentation layer also operate with domain objects. So whenever a user would perform a customer search, the presentation layer would do something like this:
Criteria crit = new Criteria(Customer.class);
crit.add(Expression.eq("name", "bob"));
// pass crit to an EJB
The EJB would just then run the criteria against a Hibernate session. The problem is that Criteria can only be obtained from Session itself. In OJB, for example, Criteria could be instantiated on its own which is very slick.
Basically, I don't want to do extra coding if I don't see a need for it. I cannot see a clear way to pass search criteria between presentation layer and Hibernate/EJB3 in a business layer. Any advices or best practices?
Regards,
Yuriy
|