我遇到了以下问题:
我有三个POJO:
Artist.class:
当我调用trackService.deleteTrack(track_id);时,我的MySQL数据库中的轨迹未被删除。Hibernate只是输出大量的select语句。
如有需要,请告知更多信息,感激不尽。
我有三个POJO:
- Artist(艺术家)
- Album(专辑)
- Track(曲目)
Artist.class:
@Entity
public class Artist {
@Id
@GeneratedValue
@Column(name = "artist_id")
private long artist_id;
@Column(name = "artist_name", nullable = false, length = 32)
private String artist_name;
@Column(name = "artist_bio", nullable = false, length = 255)
private String artist_bio;
@Lob
@Basic(fetch = FetchType.EAGER)
@Column(name = "artist_avatar")
private byte[] artist_avatar;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "artist", orphanRemoval = true)
private List<Album> albumList;
Album.class
@Entity
public class Album {
@Id
@GeneratedValue
@Column(name = "album_id")
private long album_id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "artist_id", nullable = false)
private Artist artist;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "album", orphanRemoval = true)
private List<Track> trackList;
@Column(name = "album_name", nullable = false, length = 32)
private String album_name;
@Column(name = "album_description", nullable = false, length = 255)
private String album_description;
@Lob
@Basic(fetch = FetchType.EAGER)
@Column(name = "album_avatar")
private byte[] album_avatar;
Track.class
@Entity
public class Track {
@Id
@GeneratedValue
@Column(name = "track_id")
private long track_id;
@Column(name = "track_no", nullable = false, length = 2)
private String track_no;
@Column(name = "track_name", nullable = false, length = 32)
private String track_name;
@Column(name = "track_length", nullable = false, length = 32)
private String track_length;
@Column(name = "track_file", nullable = false, length = 128)
private String track_file;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "album_id", nullable = false)
private Album album;
跟踪Controller.class
@RequestMapping(value = "/track", params = "delete", method = RequestMethod.POST)
@Transactional
public String postDeleteTrack(@RequestParam Long album_id, Long track_id) {
trackService.deleteTrack(track_id);
return "redirect:album/" + album_id;
}
追踪 Service.class
public void deleteTrack(Long track_id) {
trackRepository.delete(track_id);
}
TrackRepository.class
@Repository
public interface TrackRepository extends CrudRepository<Track, Long>{
}
当我调用trackService.deleteTrack(track_id);时,我的MySQL数据库中的轨迹未被删除。Hibernate只是输出大量的select语句。
如有需要,请告知更多信息,感激不尽。