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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 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.
In case you’re wondering, this was done in the runtime configuration before copying the logs for this chapter.
- 5.
If you want to see them all and be amazed, see http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch16.html#queryhql-expressions. There are a lot.
- 6.
See http://xkcd.com/327/. You’re welcome.
- 7.
This join results in a projection, thus the use of the Object arrays.
- 8.
Our test code uses a bulk delete to clear out the data, including the use of executeUpdate(), as mentioned earlier.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2014 Joseph B. Ottinger
About this chapter
Cite this chapter
Ottinger, J.B., Minter, D., Linwood, J. (2014). Searches and Queries. In: Beginning Hibernate. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4302-6518-4_9
Download citation
DOI: https://doi.org/10.1007/978-1-4302-6518-4_9
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4302-6517-7
Online ISBN: 978-1-4302-6518-4
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)