Fix mappings
This commit is contained in:
parent
87ffe9dc51
commit
6db6c6b2e5
@ -8,13 +8,10 @@ import java.util.Collection;
|
||||
|
||||
@Entity
|
||||
public class Driver extends PlatformUser implements IDriver {
|
||||
@OneToMany(targetEntity = Match.class)
|
||||
private Collection<IMatch> matches = new ArrayList<>();
|
||||
|
||||
@ManyToOne(targetEntity = Vehicle.class, optional = false)
|
||||
private IVehicle vehicle;
|
||||
|
||||
@OneToMany(targetEntity = Employment.class)
|
||||
@ManyToMany(targetEntity = Employment.class)
|
||||
private Collection<IEmployment> employments = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
package dst.ass1.jpa.model.impl;
|
||||
|
||||
import dst.ass1.jpa.model.IDriver;
|
||||
import dst.ass1.jpa.model.IEmployment;
|
||||
import dst.ass1.jpa.model.IEmploymentKey;
|
||||
import dst.ass1.jpa.model.IOrganization;
|
||||
import org.hibernate.annotations.Target;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import static dst.ass1.jpa.util.Constants.T_DRIVER;
|
||||
import static dst.ass1.jpa.util.Constants.T_ORGANIZATION;
|
||||
|
||||
@Entity
|
||||
public class Employment implements IEmployment {
|
||||
public class Employment implements IEmployment, Serializable {
|
||||
@EmbeddedId @Target(EmploymentKey.class)
|
||||
private IEmploymentKey id;
|
||||
|
||||
@ -21,14 +18,6 @@ public class Employment implements IEmployment {
|
||||
|
||||
private Boolean active;
|
||||
|
||||
@MapsId(T_ORGANIZATION)
|
||||
@ManyToOne(targetEntity = Organization.class)
|
||||
IOrganization organization;
|
||||
|
||||
@MapsId(T_DRIVER)
|
||||
@ManyToOne(targetEntity = Driver.class)
|
||||
IDriver driver;
|
||||
|
||||
@Override
|
||||
public IEmploymentKey getId() {
|
||||
return id;
|
||||
|
||||
@ -7,7 +7,6 @@ import dst.ass1.jpa.model.IOrganization;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Embeddable
|
||||
public class EmploymentKey implements IEmploymentKey, Serializable {
|
||||
@ -17,9 +16,6 @@ public class EmploymentKey implements IEmploymentKey, Serializable {
|
||||
@ManyToOne(targetEntity = Organization.class)
|
||||
private IOrganization organization;
|
||||
|
||||
public EmploymentKey() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDriver getDriver() {
|
||||
return driver;
|
||||
@ -39,17 +35,4 @@ public class EmploymentKey implements IEmploymentKey, Serializable {
|
||||
public void setOrganization(IOrganization organization) {
|
||||
this.organization = organization;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
EmploymentKey that = (EmploymentKey) o;
|
||||
return getDriver().equals(that.getDriver()) && getOrganization().equals(that.getOrganization());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getDriver(), getOrganization());
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,9 +16,6 @@ public class Location implements ILocation {
|
||||
|
||||
private Long locationId;
|
||||
|
||||
@ManyToMany(targetEntity = Trip.class)
|
||||
private Collection<ITrip> trips = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package dst.ass1.jpa.model.impl;
|
||||
|
||||
import dst.ass1.jpa.model.*;
|
||||
import org.hibernate.annotations.Target;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
@ -12,16 +13,16 @@ public class Match implements IMatch {
|
||||
|
||||
private Date date;
|
||||
|
||||
@Embedded
|
||||
@Embedded @Target(Money.class)
|
||||
private IMoney fare;
|
||||
|
||||
@OneToOne(targetEntity = Trip.class)
|
||||
private ITrip trip;
|
||||
|
||||
@ManyToOne(targetEntity = Vehicle.class)
|
||||
@OneToOne(targetEntity = Vehicle.class)
|
||||
private IVehicle vehicle;
|
||||
|
||||
@ManyToOne(targetEntity = Driver.class)
|
||||
@OneToOne(targetEntity = Driver.class)
|
||||
private IDriver driver;
|
||||
|
||||
@Override
|
||||
|
||||
@ -3,12 +3,12 @@ package dst.ass1.jpa.model.impl;
|
||||
import dst.ass1.jpa.model.IMoney;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Embeddable
|
||||
public class Money implements IMoney {
|
||||
public class Money implements IMoney, Serializable {
|
||||
private String currency;
|
||||
|
||||
private BigDecimal value;
|
||||
|
||||
@Override
|
||||
|
||||
@ -6,16 +6,13 @@ import dst.ass1.jpa.model.ITrip;
|
||||
import org.hibernate.annotations.Cascade;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static dst.ass1.jpa.util.Constants.*;
|
||||
|
||||
@Entity
|
||||
@Table(
|
||||
uniqueConstraints = @UniqueConstraint(columnNames = {M_RIDER_ACCOUNT, M_RIDER_BANK_CODE})
|
||||
)
|
||||
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {M_RIDER_ACCOUNT, M_RIDER_BANK_CODE}))
|
||||
public class Rider extends PlatformUser implements IRider {
|
||||
@Column(unique = true) @NotNull
|
||||
private String email;
|
||||
@ -34,7 +31,7 @@ public class Rider extends PlatformUser implements IRider {
|
||||
@JoinColumn(name = I_PREFERENCES, unique = true)
|
||||
private IPreferences preferences;
|
||||
|
||||
@ManyToOne(targetEntity = Trip.class)
|
||||
@OneToMany(targetEntity = Trip.class)
|
||||
private Collection<ITrip> trips = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
|
||||
@ -3,6 +3,7 @@ package dst.ass1.jpa.model.impl;
|
||||
import dst.ass1.jpa.model.IMoney;
|
||||
import dst.ass1.jpa.model.ITrip;
|
||||
import dst.ass1.jpa.model.ITripInfo;
|
||||
import org.hibernate.annotations.Target;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
@ -16,7 +17,7 @@ public class TripInfo implements ITripInfo {
|
||||
|
||||
private Double distance;
|
||||
|
||||
@Embedded
|
||||
@Embedded @Target(Money.class)
|
||||
private IMoney total;
|
||||
|
||||
private Integer driverRating;
|
||||
|
||||
@ -20,15 +20,6 @@ public class Vehicle implements IVehicle {
|
||||
|
||||
private String type;
|
||||
|
||||
@OneToMany(targetEntity = Driver.class)
|
||||
private Collection<IDriver> driver;
|
||||
|
||||
@OneToMany(targetEntity = Match.class)
|
||||
private Collection<IMatch> match;
|
||||
|
||||
@ManyToMany(mappedBy = "vehicles", targetEntity = Organization.class)
|
||||
private Collection<IOrganization> organization;
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user