@Entity
@Table(name = "artist")
public class Artist {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer ArtistId;
@Column(name = "Name")
private String Name;
@OneToMany(mappedBy = "artist",fetch = FetchType.EAGER)
@JsonIgnoreProperties("artist")
private Set<Album> albums = new HashSet<>();
public Integer getArtistId() {
return ArtistId;
}
public void setArtistId(Integer artistId) {
ArtistId = artistId;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public Set<Album> getAlbums() {
return albums;
}
public void setAlbums(Set<Album> albums) {
this.albums = albums;
}
}
le fichier album
@Entity
@Table(name = "album")
public class Album {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer AlbumId;
@Column(name = "Title")
private String Title;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "ArtistId")
private Artist artist;
public Integer getAlbumId() {
return AlbumId;
}
public void setAlbumId(Integer albumId) {
AlbumId = albumId;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public Artist getArtist() {
return artist;
}
public void setArtist(Artist artist) {
this.artist = artist;
}
}
Voilà le il manquait le
fetch = FetchType.EAGER
C'est lui qui empêchait le requêtage pour afficher les albums.
[Spring] connexion à la base de donnée
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.