This repository was archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
annotations_collections
Otávio Santana edited this page Feb 6, 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.
@Entity(name="resumebook")
public class Book {
@Id
@Column(name="booksname")
private String name;
@MapData
private Map chapterResume;
//getter and setter
}
@Entity(name="shopping")
public class ShoppingList {
@Id
private String name;
@Column(name="day")
private Date day;
@ListData
@Column(name="frutis")
private List fruits;
@Column(name="storeName")
private String storeName;
//getter and setter
}
@Entity(name="contact")
public class Contact implements Serializable {
@Id
@Column(name="id")
private String name;
@Column(name="emails")
@SetData
private Set<String> emails;
//getter and setter
}
@Entity(name = "collection")
public class CollectionBean {
@Id
private UUID id;
@ElementCollection
@Column(name = "mapBean")
private Map<String, String> map;
@ElementCollection
@Column(name = "setBean")
private Set<String> set;
@ElementCollection
@Column(name = "listBean")
private List<String> list;
// getter and setter
}