Garmaine Staff asked 1 year ago

I'm trying to map User and Script, my main goal is that a user can create many script and own many scripts but Script can be created only by one user and be owned by many

public class Script {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
@NotBlank(message = "Script name cannot be empty")
@Column(unique = true)
private String scriptName;
private boolean enabled;
@ManyToOne
private User author;
@ManyToMany(cascade = CascadeType.ALL, mappedBy = "ownedScripts")
private List<User> users = new ArrayList<>();

public class User {
@Id
@Column(updatable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
@NotBlank(message = "Username cannot be empty")
@Column(unique = true)
private String discordUsername;
@NotBlank(message = "Password cannot be empty")
private String password;
private boolean enabled;
private Role role;
@ManyToMany(cascade = CascadeType.ALL)
private List<Script> ownedScripts = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL)
private List<Script> createdScripts = new ArrayList<>();