Skip to main content
Top

2016 | OriginalPaper | Chapter

9. Searches and Queries

Authors : Joseph B. Ottinger, Jeff Linwood, Dave Minter

Published in: Beginning Hibernate

Publisher: Apress

Activate our intelligent search to find suitable subject content or patents.

search-config
loading …

Abstract

In the last chapter, we discussed how the Hibernate session is used to interact with the database. Some of the session's methods take query strings in their parameter lists or return Query objects. These methods are used to request arbitrary information from the database. In order to fully show how they're used, we must introduce the Hibernate Query Language (HQL), used to phrase these requests. As well as extracting information (with SELECT), HQL can be used to alter the information in the database (with INSERT, UPDATE, and DELETE). We cover all of this basic functionality in this chapter. Note: Hibernate's query facilities do not allow you to alter the database structure.

Dont have a licence yet? Then find out more about our products and how to get one now:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Footnotes
1
Lombok works by analyzing Java source code. It does not walk a hierarchy; while this would be very useful, there are some real technical challenges to implementation. While someday Lombok may indeed be able to handle object hierarchies as conveniently as it handles simple objects, as of this writing it doesn’t work well for object hierarchies, so we’re not going to use it in this chapter.
 
2
There are lots of ways to do this; we could use a technique we used earlier in the book and create a new SessionFactory for each test, or we could use dbUnit ( http://dbunit.sourceforge.net/ ). This just seems more direct.
 
3
If you’re using the JPA configuration, the property name is “hibernate.show_sql.
 
4
Well, debug or whatever equivalent your logging library might use…
 
5
In case you’re wondering, this was done in the runtime configuration before copying the logs for this chapter.
 
6
If you want to see them all and be amazed, see http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#hql . There are a lot of expressions available through JPA, and Hibernate itself adds quite a few.
 
7
See http://xkcd.com/327/ . You’re welcome.
 
8
It’s possible to triage queries yourself, of course; all you have to do is validate the query with a grammar to allow the expressions you want. In the real world, most of us can’t justify the time and effort this entails. Don’t do it. Use the facilities that Hibernate makes available to you.
 
9
This join results in a projection, thus the use of the Object arrays.
 
10
Our test code uses a bulk delete to clear out the data, including the use of executeUpdate(), as mentioned earlier.
 
Metadata
Title
Searches and Queries
Authors
Joseph B. Ottinger
Jeff Linwood
Dave Minter
Copyright Year
2016
Publisher
Apress
DOI
https://doi.org/10.1007/978-1-4842-2319-2_9

Premium Partner