Hibernate 3 provides a an extensive but easy-to-use system for vetting data submitted to an entity object.
Presentation - Going Beyond JPA with Hibernate 3
Hibernate 3 is a superset of the JPA. In this session, we look at some of the "added value" extensions offered by Hibernate 3.
- Criteria Queries
- Annotation Extensions
- Validator
- Search
- Shards
Workshop - Register extensions
In the lab, we use the Hibernate validator to prevent "garbage" input.
Story: Values submitted by the Register form must be the correct type, and some values are required.
- Utilize the Hibernate Validator to confirm input with annotations
Prerequisites
- @NotEmpty
- @Length
Exercises
- Use Hibernate Validator classes (org.hibernate.validator.*) to annotate the User entity to realize the extensions to the Register Use Case
- Username and Password are required
- Password length must be at least 4 characters and no more than 10
- Full Name is required
- From Address and Reply To Addresses must be email addresses
- Write unit tests to prove the validations work!
Hint code
Accomplishments
- Utilized the Hibernate Validator to confirm input with annotations
Extra Credit
- Annotate and test Subscription and Protocol
- Use the @ForeignKey annotation to give the Derby constraints sensible names
- Use @GeneratedValue to create UUIDs for the User, Subscription, and Protocol IDs.
