[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hibernate Query By Example

Posted on 2005-05-12
15
Medium Priority
?
3,198 Views
Last Modified: 2010-05-18
Hello,
 
      can anyone tell me where i can find the documentation on this ??

      I searched for it , but couldnt find.

Thanks.
0
Comment
Question by:letsbedecent
  • 5
  • 4
  • 2
  • +3
15 Comments
 

Author Comment

by:letsbedecent
ID: 13987448
Hey,

      Its not HQL i am asking about. Its Hibernate QBE ( a part of hibernate QBC).  I found documentation on QBC, but not QBE... thats what i am looking for.

Thank you.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 37

Expert Comment

by:zzynx
ID: 13987457
Or do you mean this: http://www.hibernate.org/5.html?
0
 

Author Comment

by:letsbedecent
ID: 13987458
nope
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13987466
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 1000 total points
ID: 13987950
0
 
LVL 3

Expert Comment

by:lilian-arnaud
ID: 13988813
User exampleUser = new User();
 exampleUser.setFirstname("Max");
 Criteria criteria = session.createCriteria(User.class);
 criteria.add( Example.create(exampleUser) );
 List result = criteria.list();
 
0
 

Author Comment

by:letsbedecent
ID: 13988834
Thank you.,

  what if the exampleUser has a mapping to Office object.  (many to one). and now i want to get all users within the office of "Experts Exchange" having a name "mike"

??

Thank you.
0
 
LVL 2

Expert Comment

by:patbin
ID: 13989597
0
 

Author Comment

by:letsbedecent
ID: 13989622
I dont want to use HQL.

i want to use the hibernates capability of retrieving records by criteria  /  example.
0
 
LVL 15

Accepted Solution

by:
aozarov earned 1000 total points
ID: 13989638
In addition to TimYates link you can see http://www.hibernate.org/hib_docs/v3/reference/en/html/querycriteria.html for Hiberate V3 documentation.
This are the relevant javadoc links:
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Criteria.html
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/Restrictions.html

This can be one way of doing it:
Criteria criteria = session.createCriteria(User.class);
criteria.add( Restrictions.eq("name", "mike") );  // filter users only with name 'mike' (as seen above)
criteria.add( Restrictions.sqlRestriction("{alias}.office.name = 'Experts Exchange'")); // apply HQL filter for related office with name = 'Experts Exchange'
List result = criteria.list();
0
 

Author Comment

by:letsbedecent
ID: 13989666
Where do you specify the {alias} name ??
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13989695
{alias} will be replaced with the name of the table (hibernta does it for you)
see: http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/Restrictions.html#sqlRestriction(java.lang.String)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 14016544
:-)

Good luck!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question