Create Employment relationship
This commit is contained in:
parent
230d170b58
commit
37b60c4eeb
@ -0,0 +1,58 @@
|
||||
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.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 {
|
||||
@EmbeddedId @Target(EmploymentKey.class) private IEmploymentKey id;
|
||||
private Date since;
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(IEmploymentKey employmentKey) {
|
||||
this.id = employmentKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getSince() {
|
||||
return since;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSince(Date since) {
|
||||
this.since = since;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(Boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package dst.ass1.jpa.model.impl;
|
||||
|
||||
import dst.ass1.jpa.model.IDriver;
|
||||
import dst.ass1.jpa.model.IEmploymentKey;
|
||||
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 {
|
||||
@ManyToOne(targetEntity = Driver.class)
|
||||
IDriver driver;
|
||||
|
||||
@ManyToOne(targetEntity = Organization.class)
|
||||
IOrganization organization;
|
||||
|
||||
public EmploymentKey() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDriver getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDriver(IDriver driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOrganization getOrganization() {
|
||||
return organization;
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user