Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Java Hibernate Cookbook

You're reading from   Java Hibernate Cookbook Over 50 recipes to help you build dynamic and powerful real-time Java Hibernate applications

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781784391904
Length 250 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Setting Up Hibernate FREE CHAPTER 2. Understanding the Fundamentals 3. Basic Annotations 4. Working with Collections 5. Working with Associations 6. Querying 7. Advanced Concepts 8. Integration with Other Frameworks Index

Persisting Set

Set provides an unordered data structure, and duplicate elements are not allowed. Some classes implemented by the Set interface are java.util.HashSet, java.util.LinkedHashSet, and so on. For this recipe, we will use the java.util.HashSet class, which implements the java.util.Set interface. The only difference between List and Set is that Set doesn't allow duplicate values. For example, in our previous example, we added the e-mail address with emailaddress3@provider3.com twice, and hibernate will allow us to do this. But in case of Set, you cannot add a duplicate value. Let's take a look at how to achieve this.

Getting ready

Now, we need the class to persist Set in hibernate. Use the next code snippet to create the Employee class.

Creating a class

Use the following code to create the classes:

Source file: Employee.java

@Entity
@Table(name = "employee")
public class Employee {

  @Id
  @GeneratedValue
  @Column(name = "id")
  private long id;

  @Column...
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
Banner background image