Commit c71ec945 authored by Andrei Zhikulin's avatar Andrei Zhikulin
Browse files

add ManyToMany

parent 3b55803a
package server.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import server.dto.AirlineDto;
import server.model.AirlineEntity;
import server.service.AirlineService;
......
......@@ -2,6 +2,7 @@ package server.dto;
import org.modelmapper.ModelMapper;
import server.model.FlightEntity;
import server.model.PassengerEntity;
import server.model.TicketEntity;
import javax.validation.constraints.NotNull;
......@@ -31,7 +32,6 @@ public class FlightDto {
// private AirlineEntity airlineByAirlineid;
// @NotNull
// private TerminalEntity terminalByTerminalid;
@NotNull
private List<TicketEntity> ticketsById;
public int getId() {
......
package server.dto;
import org.modelmapper.ModelMapper;
import server.model.FlightEntity;
import server.model.PassengerEntity;
import javax.validation.constraints.NotNull;
import java.util.Set;
public class PassengerDto {
......
......@@ -2,8 +2,6 @@ package server.dto;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import server.model.FlightEntity;
import server.model.PassengerEntity;
import server.model.TicketEntity;
import javax.validation.constraints.NotNull;
......
package server.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.annotations.CreationTimestamp;
import org.springframework.core.annotation.Order;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@Entity
@Table(name = "flight", schema = "airbook", catalog = "ear2018zs_22")
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class FlightEntity {
@Id
private int id;
private int planeid;
private int airlineid;
......@@ -133,11 +142,11 @@ public class FlightEntity {
Objects.equals(arrival, that.arrival);
}
@Override
public int hashCode() {
return Objects.hash(id, planeid, airlineid, departmentdate, arrilvalsdate, department, arrival, distance, terminalid);
}
// @Override
// public int hashCode() {
//
// return Objects.hash(id, planeid, airlineid, departmentdate, arrilvalsdate, department, arrival, distance, terminalid);
// }
@JsonIgnore
@ManyToOne(cascade = {CascadeType.PERSIST})
......@@ -170,4 +179,26 @@ public class FlightEntity {
public void setTicketsById(List<TicketEntity> ticketsById) {
this.ticketsById = ticketsById;
}
}
private List<PassengerEntity> passengers;
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "ticket", catalog = "airbook", joinColumns = {
@JoinColumn(name = "flightid", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "passengerid",
nullable = false, updatable = false) })
// @ManyToMany(cascade = {CascadeType.MERGE})
// @JoinTable(name = "ticket",
// joinColumns = @JoinColumn(name = "flightid", referencedColumnName = "id"),
// inverseJoinColumns = @JoinColumn(name = "passengerid", referencedColumnName = "id"))
// @JsonIgnoreProperties("passengers")
public List<PassengerEntity> getPassengers() {
return passengers;
}
public void setPassengers(List<PassengerEntity> passengers) {
this.passengers = passengers;
}
}
\ No newline at end of file
package server.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.annotations.Target;
import javax.persistence.*;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@Entity
@Table(name = "passenger", schema = "airbook", catalog = "ear2018zs_22")
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class PassengerEntity {
private int id;
private String email;
......@@ -88,11 +98,11 @@ public class PassengerEntity {
Objects.equals(password, that.password);
}
@Override
public int hashCode() {
// @Override
// public int hashCode() {
// return Objects.hash(id, email, name, surname, password, phonenumber);
// }
return Objects.hash(id, email, name, surname, password, phonenumber);
}
@OneToMany(cascade = {CascadeType.ALL}, orphanRemoval = true, mappedBy = "passengerByPassengerid")
public List<TicketEntity> getTicketsById() {
......@@ -102,4 +112,21 @@ public class PassengerEntity {
public void setTicketsById(List<TicketEntity> ticketsById) {
this.ticketsById = ticketsById;
}
}
private List<FlightEntity> flights;
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "passengers")
// @ManyToMany(cascade = {CascadeType.MERGE})
// @JoinTable(name = "ticket",
// joinColumns = @JoinColumn(name = "passengerid", referencedColumnName = "id"),
// inverseJoinColumns = @JoinColumn(name = "flightid", referencedColumnName = "id"))
// @JsonIgnoreProperties("flights")
public List<FlightEntity> getFlights() {
return flights;
}
public void setFlights(List<FlightEntity> flights) {
this.flights = flights;
}
}
\ No newline at end of file
......@@ -5,10 +5,12 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.math.BigInteger;
import java.util.Objects;
import java.util.Set;
@Entity
@Table(name = "ticket", schema = "airbook", catalog = "ear2018zs_22")
public class TicketEntity {
@Id
private int id;
private int passengerid;
private int flightid;
......@@ -82,7 +84,6 @@ public class TicketEntity {
@Override
public int hashCode() {
return Objects.hash(id, passengerid, flightid, price, seatnumber);
}
......@@ -107,4 +108,4 @@ public class TicketEntity {
public void setFlightByFlightid(FlightEntity flightByFlightid) {
this.flightByFlightid = flightByFlightid;
}
}
}
\ No newline at end of file
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://kbss.felk.cvut.cz:5433/ear2018zs_22?username=ear2018zs_22&password=Seledka14
spring.datasource.url=jdbc:postgresql://kbss.felk.cvut.cz:5433/ear2018zs_22?username=ear2018zs_22&password=Seledka14&searchpath=airbook
spring.datasource.username=ear2018zs_22
spring.datasource.hikari.maximum-pool-size=1
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
......@@ -9,7 +9,7 @@ spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
spring.datasource.password=Seledka14
#spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
......
......@@ -9,7 +9,6 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import server.dto.FlightDto;
import server.model.FlightEntity;
import server.repositories.FlightRepository;
import server.service.FlightService;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment