Persisting Array

Working with Array is similar to that with List, but in List, it is not compulsory to add @IndexColumn. However, Array requires an indexed column to maintain the column order.

Getting ready

Create the required class using the following code to persist Array:

Source file: Employee.java

@Entity @Table(name = "employee") public class Employee { @Id @GeneratedValue @Column (name = "id") private long id; @Column (name = "name") private String name; @ElementCollection @IndexColumn(name="email_index") @CollectionTable(name = "email") private String[] emails; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public ...

Get Java Hibernate Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.