package com.phonoforce.tramory.entities; import javax.persistence.*; import javax.xml.bind.annotation.*; import java.util.HashSet; import java.util.Set; import static javax.persistence.GenerationType.IDENTITY; @Entity @Table(name = "Artist") @XmlRootElement(name = "artist") @XmlAccessorType(XmlAccessType.FIELD) public class Artist implements IEntity { @XmlElement(required = true) private int artistId; @XmlElement(required = true) private String biography; @XmlElement(required = true) private String pseudonym; @XmlElement(required = true) private String url; @XmlTransient /*@XmlElementWrapper(name = "albums") @XmlElement(name = "album", required = true)*/ private Set<Album> albums; public Artist() { this.albums = new HashSet<>(); } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "artist_id", unique = true, nullable = false) public int getId() { return artistId; } public void setId(int artistId) { this.artistId = artistId; } @Column(name = "biography", nullable = true) public String getBiography() { return biography; } public void setBiography(String biography) { this.biography = biography; } @Column(name = "pseudonym", nullable = false) public String getPseudonym() { return pseudonym; } public void setPseudonym(String pseudonym) { this.pseudonym = pseudonym; } @Column(name = "url", nullable = true) public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } @ManyToMany( cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "artists" ) public Set<Album> getAlbums() { return this.albums; } public void setAlbums(Set<Album> albums) { this.albums = albums; } @Override public String toString() { return "Artist{" + "artistId=" + artistId + ", biography='" + biography + '\'' + ", pseudonym='" + pseudonym + '\'' + ", url='" + url + '\'' + '}'; } }