DEV Community

Discussion on: Introducing One To Many Relationship in Angular & Akita

Collapse
 
crmiguez profile image
Crmiguez • Edited

Great tutorial, Ariel, but I am searching for a new scenario. What about in this classes below in Java, please?

public class User implements Serializable, UserDetails {

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Size(max = 36)
@Column(name = "userId")
private String userId;

@JoinColumn(name = "accountId", referencedColumnName = "accountId", nullable = false)
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonInclude(JsonInclude.Include.NON_NULL)
private Account account;

@Column(name = "userName")
private String userName;

@Column(name = "emailAddress")
private String emailAddress;

@Column(name = "password")
private String password;

...
}

public class Account implements Serializable {

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Size(max = 36)
@Column(name = "accountId")
private String accountId;

@Column(name = "accountName")
private String accountName;

@Column(name = "company")
private String company;

@Column(name = "address")
private String address;

@Column(name = "emailAddress")
private String emailAddress;

@Column(name = "dicomId")
private String dicomId;

@Column(name = "enabled")
@ColumnDefault(value = "1")
private Integer enabled;

@OneToMany (mappedBy = "account",
            cascade = CascadeType.ALL,
            orphanRemoval = true)
Set<User> users = new HashSet<>();

...
}

Thanks in advance! :)