This is an example of how our Delphi developers pull some bits of the licence details and vehicle details of an operator. I'm designing a model to suit an existing database, so i don't have a lot of room
Code:
Select
lic_id,
lic_numb,
veh_id,
Veh_reg_no,
veh_no_passengers
from Licences
left outer join lictype on lty_id = lic_typ_id
left outer join clients on cli_id = lic_cli_id_resp
left outer join vehicles on veh_id = lic_veh_id
where lic_opr_id = 5
#opr_id = 5
key opr=operator
veh= vehicles
cli=clients
the rest is obvious
Does it mean I always have to select licences. This is how my model looks now
Code:
@Entity
@Table(name="operators")
public class LpOperator implements Serializable{
private int id;
private String postCode;
private String operatorName;
private String ward;
private String operatorRegistrationBumber;
private int operatorType;
private Set<LpVehicle> vehicles;
private Set<LpLicence> licences;
public LpOperator() {
}
@Id
@Column(name="opr_id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="opr_registration_number")
public String getOperatorRegistrationBumber() {
return operatorRegistrationBumber;
}
public void setOperatorRegistrationBumber(String operatorRegistrationBumber) {
this.operatorRegistrationBumber = operatorRegistrationBumber;
}
@Column(name="opr_off_postcode")
public String getPostCode() {
return postCode;
}
public void setPostCode(String postCode) {
this.postCode = postCode;
}
@Column(name="opr_name")
public String getOperatorName() {
return operatorName;
}
public void setOperatorName(String operatorName) {
this.operatorName = operatorName;
}
@Column(name="opr_type")
public int getOperatorType() {
return operatorType;
}
public void setOperatorType(int operatorType) {
this.operatorType = operatorType;
}
@Column(name="opr_type")
public String getWard() {
return ward;
}
public void setWard(String ward) {
this.ward = ward;
}
@ManyToMany(
targetEntity=LpVehicle.class,
mappedBy="vehicles",
fetch=FetchType.EAGER
)
@JoinTable(name="client"??,
Dont know what to put here
)
public Set<LpVehicle> getVehicles() {
return vehicles;
}
public void setVehicles(Set<LpVehicle> vehicles) {
this.vehicles = vehicles;
}
@OneToMany(
mappedBy="operator",
targetEntity=LpLicence.class,
fetch=FetchType.EAGER
)
public Set<LpLicence> getLicences() {
return licences;
}
public void setLicences(Set<LpLicence> licences) {
this.licences = licences;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LpOperator other = (LpOperator) obj;
if (this.id != other.id) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 53 * hash + this.id;
return hash;
}
}