Промежуточное сохранение. Надеюсь, что будет работать
This commit is contained in:
parent
43cc05427d
commit
8a23075ac6
@ -12,12 +12,13 @@ public class GameClient {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false, length = 255)
|
@Column(name = "nickName", nullable = false, length = 255)
|
||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
@Column(nullable = false, length = 255)
|
@Column(name = "email", nullable = false, length = 255)
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "balance")
|
||||||
private Integer balance;
|
private Integer balance;
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "gameClients", fetch= FetchType.EAGER)
|
@ManyToMany(mappedBy = "gameClients", fetch= FetchType.EAGER)
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package premium_store.model;
|
package premium_store.model;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Objects;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "NATIONS")
|
@Table(name = "NATIONS")
|
||||||
@ -11,8 +10,12 @@ public class Nation {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "nation")
|
||||||
private String nation;
|
private String nation;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy ="nation", cascade = CascadeType.MERGE,fetch = FetchType.EAGER)
|
||||||
|
private List<Tank> tanks = new ArrayList<>();
|
||||||
|
|
||||||
public Nation() {
|
public Nation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +37,15 @@ public class Nation {
|
|||||||
this.nation = nation;
|
this.nation = nation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tank> getTanks(){
|
||||||
|
return tanks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNewTank(Tank tank) {
|
||||||
|
tanks.add(tank);
|
||||||
|
tank.setNation(this);
|
||||||
|
}
|
||||||
|
|
||||||
//метод для сравнения
|
//метод для сравнения
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
@ -13,16 +13,16 @@ public class Tank {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
||||||
@JoinColumn(name = "nation")
|
|
||||||
private Nation nation;
|
private Nation nation;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
||||||
@JoinColumn(name = "tankLevel")
|
|
||||||
private TankLevel tankLevel;
|
private TankLevel tankLevel;
|
||||||
|
|
||||||
|
@Column(name = "cost")
|
||||||
private int cost;
|
private int cost;
|
||||||
|
|
||||||
//реализация двунаправленной связи многие-ко-многим
|
//реализация двунаправленной связи многие-ко-многим
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package premium_store.model;
|
package premium_store.model;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Objects;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "TANKLEVELS")
|
@Table(name = "TANKLEVELS")
|
||||||
@ -11,9 +10,12 @@ public class TankLevel {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(name = "level", nullable = false)
|
||||||
private int level;
|
private int level;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "tankLevel", cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
|
||||||
|
private List<Tank> tanksOfThisLevel = new ArrayList<>();
|
||||||
|
|
||||||
public TankLevel() {
|
public TankLevel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +37,15 @@ public class TankLevel {
|
|||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tank> getTanks(){
|
||||||
|
return tanksOfThisLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNewTank(Tank tank) {
|
||||||
|
tanksOfThisLevel.add(tank);
|
||||||
|
tank.setLevel(this);
|
||||||
|
}
|
||||||
|
|
||||||
//метод для сравнения
|
//метод для сравнения
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
@ -8,4 +8,4 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
|||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.h2.console.enabled=true
|
spring.h2.console.enabled=true
|
||||||
spring.h2.console.settings.trace=false
|
spring.h2.console.settings.trace=false
|
||||||
spring.h2.console.settings.web-allow-others=false
|
spring.h2.console.settings.web-allow-others=false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user