0

I'm having some simple objects that have relationships with each other. Everything goes fine but when i publish my objects for a SOAP request it is returning null when i set a relation between client and cartrack. What am i doing wrong?

Here is my code :

@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;
    }
}
  • What do you mean by 'publish my objects for a SOAP request'? I cannot find any SOAP related code... – home Apr 16 '13 at 14:58
  • I got a soap web service, that retreives a Client. As you can see the client object has a relationship with cartrack. When the client has no relationship with any cartrack, the soap web service is returning the user object. But when the client has some cartracks, the soap web service is returning null. – user2281918 Apr 16 '13 at 15:04

0 Answers0