Introduce proper many to one relation

This commit is contained in:
Marcel Schwarz 2020-05-11 20:21:05 +02:00
parent d66ecc43b7
commit 3ca73361f0
3 changed files with 8 additions and 12 deletions

View File

@ -1,13 +1,11 @@
package de.hft.geotime.timetrackaccount;
import de.hft.geotime.user.TimetrackUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
@Data
@NoArgsConstructor
@ -21,5 +19,7 @@ public class TimetrackAccount {
private double revenue;
private String name;
private String description;
@ManyToOne
private TimetrackUser user;
}

View File

@ -33,7 +33,7 @@ public class TimetrackUser {
@OneToOne
private Role role;
@OneToMany(fetch = FetchType.LAZY)
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<TimetrackAccount> accounts;
}

View File

@ -6,10 +6,6 @@ DELETE FROM role;
INSERT INTO role (id, `name`) VALUES
(1, 'Admin');
INSERT INTO timetrack_account (id, description, `name`, revenue) VALUES
(1, 'Gleitzeit Marcel', 'Primary Marcel', 16.0),
(2, 'Festgeld Marcel', 'Secondary Marcel', 25.0);
/* password is the firstname in lowercase e.g. marcel or tobias
https://bcrypt-generator.com/ with 10 rounds
*/
@ -19,8 +15,8 @@ INSERT INTO timetrack_user (id, firstname, lastname, password, username, role_id
(3, 'Tim', 'Zieger' ,'$2y$10$pYGHZhoaelceImO7aIN4nOkWJBp.oqNGFYaRAonHkYF4u9ljqPelC', 'ziti', 1),
(4, 'Simon', 'Kellner' ,'$2y$10$Puzm/Nr/Dyq3nQxlkXGIfubS5JPtXJSOf2e6mrQ6HhVYQN9YiQQsC', 'kesi', 1);
INSERT INTO timetrack_user_accounts (timetrack_user_id, accounts_id) VALUES
(1, 1),
(1, 2);
INSERT INTO timetrack_account (description, `name`, revenue, user_id) VALUES
('Gleitzeit Marcel', 'Primary Marcel', 16.0, 1),
('Festgeld Marcel', 'Secondary Marcel', 25.0, 1);
SET FOREIGN_KEY_CHECKS=1;