Good afternoon everyone.
I'm starting with Spring JSON and API Rest, I'm doing my first practice, which consists of a REST API that brings a playlist, like the following:
{
"name":"Lista 1",
"description": "Lista de canciones de Spotify",
“songs”:
[
{
"title": "",
"artist": "",
"album": "",
"year": ""
},
{
"title": "",
"artist": "" ,
"album": "",
"year": ""
},
… ]
}
For practice I would like to create a single table in BD for this JSON, so I create my Entity (I don't know if I'm correct using POJO):
package com.example.api.songs.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity(name = "songs_list")
public class SongsList {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "songs")
private List<Songs> songs;
public class Songs {
public String title;
public String artist;
public String album;
public int year;
}
}
Now I would like to start my table using JPA and spring.jpa.hibernate.ddl-auto = create, but I have doubts with the songs field, since it is a multi-dimensional array. At first something like this occurs to me, but I don't know if it's the right thing to do:
CREATE TABLE LIST_SONGS (
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
DESCRIPTION VARCHAR(50) NOT NULL,
SONGS VARCHAR[][][]
);
Or do you recommend creating 2 separate entities?