Otávio Santana edited this page Feb 5, 2014 · 7 revisions

There are annotations to work with Collections (java.util.Set, java.util.List, java.util.Map):

  • SetData informs the field is java.util.Set, it is necessary inform a class of the collection within a classData.

  • ListData informs the field is java.util.List, you should inform a class of the collections within classData.

  • MapData inform the field is java.util.Map, you should inform the key and value of the map's collection with classkey and classValue respectively.

  • ElementCollection by standardization of JPA 2.0 this annotation recognize automatically the collection, but this collection just can be: java.util.List, java.util.Set and java.util.Map.


 public class Book {

 private String name;

 private Map chapterResume;
 //getter and setter


 public class ShoppingList {

 private String name;

 private Date day;

 private List fruits;

 private String storeName;

 //getter and setter



 public class Contact implements Serializable {

 private String name;

 private Set<String> emails;

 //getter and setter



    @Entity(name = "collection")
    public class CollectionBean {

private UUID id;

@Column(name = "mapBean")
private Map<String, String> map;

@Column(name = "setBean")
private Set<String> set;

@Column(name = "listBean")
private List<String> list;
    // getter and setter