@ElementCollection is new annotation introduced in JPA 2.0, This will help us get rid of One-Many and Many-One shitty syntax. Example 1: Stores list of Strings in an Entity @Entity public class Users implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ElementCollection private List<String> certifications = new ArrayList <String> (); public Long getId() { return id; } public void setId(Long id) { this.id = id; } public List <String> getCertifications() { return certifications; } public void setCertifications(List <String> certifications) { this.certifications = certifications; } .. } Users u = new Users(); u.getCertifications().add("Sun Certified Java Programmer"); em.persist(u); Generated Tables Users Co
Comments