-->
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.  [ 4 posts ] 
Author Message
 Post subject: Best practices when using Hibernate JPA?
PostPosted: Sun May 08, 2011 5:07 pm 
Newbie

Joined: Sat May 07, 2011 9:56 pm
Posts: 7
Hi,

I'm starting a new project using Hibernate JPA. In the past I've used Hibernate sessions/templates, so the method of using the Entity Manager is new to me and a learning experience.

In the past I've been able to use HibernateTemplate findByCriteria method to find rows in the DB that match a model profile. I don't seem to see any similar method in the entity manager definition.

Given that this method does not exist in the JPA model, is it "missing" or rather intentionally left out as it is bad practice?

What is better practice - to specify parameters individually, or to pass a sample model populated with the parameters that you are searching for?

It wouldn't be particularly difficult to write my own "findByCriteria" equivalent in a JPA model, but I don't know if it is bad practice to do so.

Any advice would be greatly appreciated.

Thanks!

Eric


Top
 Profile  
 
 Post subject: Re: Best practices when using Hibernate JPA?
PostPosted: Sun May 08, 2011 8:40 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hibernate is usually a step ahead than the standard, but criteria queries where introduced in JPA2 :
http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html_single/#querycriteria

If you're using JPA v1, then it's not available but you could still use Hibernate's API which provides it, unless you're required to use only portable apis.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Best practices when using Hibernate JPA?
PostPosted: Sun May 08, 2011 10:13 pm 
Newbie

Joined: Sat May 07, 2011 9:56 pm
Posts: 7
Thanks for the tip. I had a v1.0 of javax.persistence lib in my pom.xml so that entity manager was overriding the one provided by hibernate 3.6. Removed it, and I now have access to the createQuery(criteria) method.

Is using critieria objects like that considered "Best Practice", or is specifying individual parameters in a search query more appropriate?

Thanks,

Eric


Top
 Profile  
 
 Post subject: Re: Best practices when using Hibernate JPA?
PostPosted: Mon May 09, 2011 8:59 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
both are good practices, one might be a better fit than the other according to what you need to do: think of what's more practical.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.