我有一些相互关联的简单对象。一切都很好,但是当我为 SOAP 请求发布我的对象时,当我设置客户端和 cartrack 之间的关系时,它返回 null。我究竟做错了什么?
这是我的代码:
@Entity
public class Client extends User implements Serializable {
@Temporal(javax.persistence.TemporalType.DATE)
private Date birthdate;
private String address;
private String zipcode;
private String city;
private String phone;
private String info;
private boolean active;
@OneToMany( cascade = CascadeType.ALL,
fetch = FetchType.EAGER,
targetEntity = Cartrack.class,
mappedBy = "client"
)
private List<Cartrack> cartracks;
/**
* @return the birthdate
*/
public Date getBirthdate() {
return birthdate;
}
/**
* @param birthdate the birthdate to set
*/
public void setBirthdate(Date birthdate) {
this.birthdate = birthdate;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}
/**
* @return the zipcode
*/
public String getZipcode() {
return zipcode;
}
/**
* @param zipcode the zipcode to set
*/
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @return the phone
*/
public String getPhone() {
return phone;
}
/**
* @param phone the phone to set
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
* @return the info
*/
public String getInfo() {
return info;
}
/**
* @param info the info to set
*/
public void setInfo(String info) {
this.info = info;
}
public String dateToString(){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(this.birthdate);
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public List<Cartrack> getCartracks() {
return cartracks;
}
public void setCartracks(List<Cartrack> cartracks) {
this.cartracks = cartracks;
}
}
@Entity
public class Cartrack implements Serializable {
@Id
private String id;
@OneToOne( mappedBy = "cartrack",
targetEntity = Vehicle.class,
cascade = CascadeType.ALL,
fetch = FetchType.EAGER
)
private Vehicle vehicle;
@ManyToOne(targetEntity = Client.class)
private Client client;
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the vehicle
*/
public Vehicle getVehicle() {
return vehicle;
}
/**
* @param vehicle the vehicle to set
*/
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Cartrack)) {
return false;
}
return ((Cartrack) obj).id == this.id;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
}
@Entity
public class Vehicle implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String licenseNr;
private boolean stolen;
@OneToOne(targetEntity = Cartrack.class)
private Cartrack cartrack;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* @return the licenseNr
*/
public String getLicenseNr() {
return licenseNr;
}
/**
* @param licenseNr the licenseNr to set
*/
public void setLicenseNr(String licenseNr) {
this.licenseNr = licenseNr;
}
/**
* @return the stolen
*/
public boolean isStolen() {
return stolen;
}
/**
* @param stolen the stolen to set
*/
public void setStolen(boolean stolen) {
this.stolen = stolen;
}
/**
* @return the cartrack
*/
public Cartrack getCartrack() {
return cartrack;
}
/**
* @param cartrack the cartrack to set
*/
public void setCartrack(Cartrack cartrack) {
this.cartrack = cartrack;
}
}