-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Entities & Criteria
PostPosted: Mon Aug 08, 2005 6:56 pm 
Newbie

Joined: Mon Aug 08, 2005 6:50 pm
Posts: 3
Greetings,

We are designing a new system and considering using EJB3 for it. One of the issues we are trying to resolve is how to pass search criteria from presentation layer to EJB layer. On the previous project we used OJB and Criteria class from OJB. It worked like a charm: presentation layer would populate Criteria object based on user's selection on a wep page and pass it to EJB where it was used as it was without any modifications. It was very convenient and uniformed. Now what does EJB3 have to offer? Presentation layer constructing EJB QL? This doesn't seem right. Presentation layer passing a Map of fields/values to be used in querying database to EJB and the EJB using it to construct EJB QL? I remember doing the same with Maps and JDBC/SQL 4 years ago and it was quite messy and not elegant at all.

I also tried to marry EJB3 and Hibernate approaches so that I could use Hibernate's Criteria class but didn't get anywhere. I got "duplicate class mapping" exception as I had both @Entity annotation and Hibernate mapping file for a specific class.

Any thoughts?

Regards,
Yuriy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 7:00 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Why would you need duplicate mapping information? Just cast your EntityManager and move on: ((HibernateEntityManager)myEntityManager).getSession().createCriteria()....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 7:01 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And, if the presentation layer can query for anything it wants, why have layering at all?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 7:17 pm 
Newbie

Joined: Mon Aug 08, 2005 6:50 pm
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://www.hibernate.org/hib_docs/v3/ap ... teria.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 11:53 am 
Newbie

Joined: Mon Aug 08, 2005 6:50 pm
Posts: 3
Thanks! That was a prompt reply.

I will take a look at DeattachedCriteria and may fire up some additional questions if I have.

Regards,
Yuriy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.