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.
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 String[] getEmails() { return emails; } public void setEmails(String[] emails) { this.emails = emails; } @Override public String toString() { return "Employee" ...