cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benson Margulies <bimargul...@gmail.com>
Subject Re: Problem with primary key in Persisted object list
Date Thu, 10 Sep 2009 18:48:26 GMT
I'm afraid that I can't follow the thread here, in part due to all the extra
whitespace.

What exactly is not happening? What version of CXF? How it is configured?


On Thu, Sep 10, 2009 at 2:01 PM, Tom Cassimon <tom@cassimon.mine.nu> wrote:

> Maybe the question belongs here, can somebody help me, i guess i'm doing
> something wrong. :-)
>
>
>
> Mail thread from users@cxf.apache.org:
>
>
>
> Hi,
>
>
>
> I have an extra problem because the primary key is not passed to the Apache
> CXF client.
>
>
>
> When i remove an element from the list it always removes the First element
> in the list. The equals method returns true.
>
>
>
> Code snippet:
>
>
>
>
> ============================================================================
>
>
>
>    @Override
>
>    public boolean equals(Object object) {
>
>        // TODO: Warning - this method won't work in the case the id fields
> are not set
>
>        if (!(object instanceof Biomechanic)) {
>
>            return false;
>
>        }
>
>        Biomechanic other = (Biomechanic) object;
>
>        if ((this.id == null && other.id != null) || (this.id != null &&
>
> !this.id.equals(other.id))) {
>
>            return false;
>
>        }
>
>        return true;
>
>    }
>
>
>
>
> ============================================================================
>
>
>
> Is there a solution to also get the primary key field filled in, in the
> objects?
>
>
>
> Regards,
>
>
>
> Tom
>
>
>
> -----Oorspronkelijk bericht-----
>
> Van: Tom Cassimon [mailto:tom@cassimon.mine.nu]
>
> Verzonden: woensdag 2 september 2009 21:58
>
> Aan: users@cxf.apache.org
>
> Onderwerp: RE: Problem with primary key in Persisted object list
>
>
>
> Hi,
>
>
>
> it's JAXWS based.
>
>
>
>
>
>
>
>    <jaxws:client id="patientService"
>
>
>
>                  serviceClass="be.tcke.podomanage.service.PatientService"
>
> address="http://localhost:8080/PodoManageServer/PatientService"/>
>
>
>
>
>
>
>
> @WebService
>
>
>
> public interface PatientService {
>
>
>
>
>
>
>
>    public List<Patient> getPatientList();
>
>
>
>
>
>
>
>      public List<Patient> getFilteredPatientList(String filter);
>
>
>
>
>
>
>
>      public Patient getPatientById(Long id);
>
>
>
>
>
>
>
>    public boolean savePatient(Patient patient);
>
>
>
> }
>
>
>
>
>
>
>
> I don't know if this is what you meant with more information, the
> getPatientById method is the one that doesn't return the id fields of the
> documents in the documentList. If this was not the info you needed, let me
> know.
>
>
>
>
>
>
>
> Regards,
>
>
>
>
>
>
>
> Tom
>
>
>
>
>
>
>
> -----Oorspronkelijk bericht-----
>
> Van: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com]
>
> Verzonden: woensdag 2 september 2009 21:51
>
> Aan: users@cxf.apache.org
>
> Onderwerp: Re: Problem with primary key in Persisted object list
>
>
>
>
>
>
>
>
>
>
>
> Hi
>
>
>
>
>
>
>
> Is it a JAXWS- or JAXRS-based application ?
>
>
>
> Can you also post some more information on how the actual CXF endpoint (or
>
>
>
> client ?) is configured ?
>
>
>
>
>
>
>
> cheers, Sergey
>
>
>
>
>
>
>
>
>
>
>
> Tom Cassimon wrote:
>
>
>
> >
>
>
>
> > Hi all,
>
>
>
> >
>
>
>
> > I have a problem with CXF. I'm using the newest version 2.2.3.
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> > I'm using Hibernate & Spring on a Tomcat Application Server and i
>
>
>
> > communicate with a Java Swing client with Apache CXF. Now everything
>
> > works
>
>
>
> > like a charm. But there is one issue. I have a persisted object on the
>
>
>
> > server with a @ManyToOne relationship.
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> >             Definition in entity class Patient:
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> >     @JoinTable(name = "patient_document", joinColumns =
>
> > {@JoinColumn(name
>
>
>
> > =
>
>
>
> > "patientId")}, inverseJoinColumns = {@JoinColumn(name =
>
> > "documentId")})
>
>
>
> >
>
>
>
> >     @OneToMany(fetch=FetchType.LAZY)
>
>
>
> >
>
>
>
> >     private List<Document> documentList;
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> >             Document entity:
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> > @Entity
>
>
>
> >
>
>
>
> > @Table(name = "document")
>
>
>
> >
>
>
>
> > public class Document implements Serializable {
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> >     private static final long serialVersionUID = 1L;
>
>
>
> >
>
>
>
> >     @Id
>
>
>
> >
>
>
>
> >     @GeneratedValue(strategy = GenerationType.IDENTITY)
>
>
>
> >
>
>
>
> >     @Basic(optional = false)
>
>
>
> >
>
>
>
> >     @Column(name = "id")
>
>
>
> >
>
>
>
> >     private Long id;
>
>
>
> >
>
>
>
> >             .
>
>
>
> >
>
>
>
> >             .
>
>
>
> >
>
>
>
> >             .
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> > I recieve the document list correct on the client side. But the id
>
> > field
>
>
>
> > is
>
>
>
> > null. This causes problems when I send the Patient class back to the
>
>
>
> > Tomcat
>
>
>
> > server for an update. Let's say I add a new document to the
>
> > documentList
>
>
>
> > in
>
>
>
> > the patient object and I want to insert it in the database. I execute
>
> > the
>
>
>
> > following code:
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> >             //Process documents
>
>
>
> >
>
>
>
> >             if (p.getDocumentList() != null) {
>
>
>
> >
>
>
>
> >                 for (Document d : p.getDocumentList()) {
>
>
>
> >
>
>
>
> >                     if (d.getId() == null)
>
>
>
> >
>
>
>
> >                         em.persist(d);
>
>
>
> >
>
>
>
> >                     else
>
>
>
> >
>
>
>
> >                         em.merge(d);
>
>
>
> >
>
>
>
> >                 }
>
>
>
> >
>
>
>
> >             }
>
>
>
> >
>
>
>
> > //Finally process patient
>
>
>
> >
>
>
>
> >             if (p.getId() == null)
>
>
>
> >
>
>
>
> >                 em.persist(p);
>
>
>
> >
>
>
>
> >             else
>
>
>
> >
>
>
>
> >                 em.merge(p);
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> > Now the problem is that the id field is null, so the code here
>
> > "thinks" it
>
>
>
> > are all new documents. He removes the links in the database and
>
> > re-inserts
>
>
>
> > all the documents. But due to another bug not cleaning up Orphans
>
>
>
> > everything
>
>
>
> > ends up more times in the database, and that is off course not wanted.
>
> > Do
>
>
>
> > I
>
>
>
> > do something wrong here or is it an actual bug? The strange thing is.
>
> > I
>
>
>
> > also
>
>
>
> > have @OneToOne relationships end there the id is submitted to the client.
>
>
>
> > I
>
>
>
> > don't see any reason for not submitting the id in @ManyToOne
>
>
>
> > relationships.
>
>
>
> > Maybe I am doing something wrong.
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> > If you need more info please ask.
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> > Regards,
>
>
>
> >
>
>
>
> >
>
>
>
> >
>
>
>
> > Tom
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message