Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Hibernate

You're reading from  Mastering Hibernate

Product type Book
Published in May 2016
Publisher Packt
ISBN-13 9781782175339
Pages 204 pages
Edition 1st Edition
Languages
Toc

Enumeration and custom data type


In this section, we see how to map "constants" to enumerated types. Constants are considered a small finite set of data elements, such as gender (Male, Female) or days of the week, such as Monday, Tuesday, and so on. Hibernate supports using enumerated types for mapping database columns containing data in a finite closed set. (The definition of a closed set comes straight from set theory.)

If you don't wish to use enumerated types, you can create a custom data type to map your data to a primitive type in Java, and you'll see that after we discuss the enumerated type.

Enumerated type

You can define an enumeration in Java and let Hibernate handle the mapping of "constants". JPA supports two kinds of enum: ORDINAL and STRING. If you use the ORDINAL enumeration type, the data in the mapped column is assumed to be an integer. You can guess how the STRING enumeration type behaves:

public enum WeekDay {
  Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime