Abstract
Hibernate provides a number of capabilities beyond the simple “native Hibernate API.” In this chapter, we are going to discuss using the standard JPA configuration resource, Hibernate’s object validation facilities, and object lifecycle events — along with a few other tricks.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
An informal survey of developers from TheServerSide Symposium 2004 indicated that nearly 95% of entity beans were being used in a way that was inefficient or improper. While informal and therefore anecdotal, that’s still a heck of a result.
- 2.
Statements like this (“X is rarely used in practice”) are almost always anecdotal. This one certainly is; you can probably find projects that fanatically rely on the Hibernate-specific annotations. The anecdote stands.
- 3.
The mechanism for using Hibernate in an environment where it’s not the default provider is fairly simple: in the persistence.xml, add <provider>org.hibernate.ejb.HibernatePersistence</provider>. You’ll still want to look up how to install Hibernate into your application server, however.
- 4.
We want a nontransitive dependency because we don’t want to force all of the modules that use the util project to include JPA support.
- 5.
Including the Platonic quality of, well, “existence.” Each of us can decide on our own if this is a compliment to The Republic or not.
- 6.
Specifically, let’s talk about boilerplate code and how to avoid having to write so much of it.
- 7.
Astute readers will note that the pom.xml already displayed has Lombok already added.
- 8.
Something your author calls a “persistence actor,” as in “something that acts on persistence,” but that sounds irrepressibly stuffy.
- 9.
The “alternative loader mechanism” refers to the use of Session.byId().load().
- 10.
For more information on cryptographic salt, see http://en.wikipedia.org/wiki/Salt_(cryptography) .
- 11.
See http://jcp.org/en/jsr/detail?id=349 for more details on this specification.
- 12.
A callback would be a validation applied through a lifecycle method; you might test a value in a method annotated with @PrePersist, for example. An external entity listener would do the same sort of thing.
- 13.
As with most things, there’s a limitation. Lombok cannot generate builders that are aware of a class hierarchy; this is caused by how Lombok works and is very difficult to get around.
- 14.
See http://en.wikipedia.org/wiki/Fluent_interface for more information on what a Fluent API is and what it can look like.
- 15.
The Validator documentation calls the level of effect on the database “Hibernate metadata impact,” such that validations of which the database is unaware have no metadata impact, but validations like @NotNull are described as meaning “Column(s) are not nullable.”
- 16.
Does anyone like lots of ado?
- 17.
If you’re interested in more detail about custom constraints—and you probably should be, if Validator interests you—see http://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/validator-customconstraints.html .
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2016 Joseph B. Ottinger, Jeff Linwood and Dave Minter
About this chapter
Cite this chapter
Ottinger, J.B., Linwood, J., Minter, D. (2016). JPA Integration and Lifecycle Events. In: Beginning Hibernate. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-2319-2_7
Download citation
DOI: https://doi.org/10.1007/978-1-4842-2319-2_7
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-2318-5
Online ISBN: 978-1-4842-2319-2
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books