I am trying to add an arraylist of double values to my mysql database using JPA and Hibernate but it is not storing the values as doubles, it is storing the arraylist object and then a lot of characters.
The image below is what the database looks like.
Arraylist
Here's my code:
Playlist.java
@Entity
public class Playlist {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String name, persistentId;
private double playlistId;
@ElementCollection
@CollectionTable(name ="tracks")
private ArrayList<Double> tracks = new ArrayList<Double>();
@OneToMany(mappedBy="playlist")
Set<Song> songs;
public Playlist(String name, String persistentId, double playlistId, ArrayList<Double> tracks) {
this.name = name;
this.persistentId = persistentId;
this.playlistId = playlistId;
this.tracks = tracks;
}
public Playlist() {
}
Main.java
Playlist p = new Playlist();
ArrayList<Double> tracks = new ArrayList<Double>();
for (int j = 0; j < tList.getLength(); ++j) {
Element track = (Element) tList.item(j);
Double trackId = (Double) x.evaluate("key[.='Track ID']/following-sibling::integer[1]", track,
XPathConstants.NUMBER);
tracks.add(trackId);
p.setTracks(tracks);
}
Could anyone tell me what I'm doing wrong please?
Try to set more informations :
@ElementCollection
@CollectionTable(name ="tracks" , joinColumns=@JoinColumn(name="playlist_id"))
@Column(name="track")
private List<Double> tracks = new ArrayList<>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With