Return-Path: Delivered-To: apmail-cxf-dev-archive@www.apache.org Received: (qmail 23247 invoked from network); 10 Sep 2009 20:07:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Sep 2009 20:07:04 -0000 Received: (qmail 65978 invoked by uid 500); 10 Sep 2009 20:07:04 -0000 Delivered-To: apmail-cxf-dev-archive@cxf.apache.org Received: (qmail 65920 invoked by uid 500); 10 Sep 2009 20:07:04 -0000 Mailing-List: contact dev-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list dev@cxf.apache.org Received: (qmail 65910 invoked by uid 99); 10 Sep 2009 20:07:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 20:07:04 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [212.71.1.210] (HELO lrelay01.edpnet.net) (212.71.1.210) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 20:06:53 +0000 Received: from cassimon.mine.nu (213.219.148.168.adsl.dyn.edpnet.net [213.219.148.168]) by lrelay01.edpnet.net (8.13.8/8.13.8) with SMTP id n8AK6TIf023193 for ; Thu, 10 Sep 2009 22:06:29 +0200 Received: (qmail 25441 invoked from network); 10 Sep 2009 20:06:28 -0000 Received: from travelmate.lan (HELO Travelmate) (192.168.182.116) by cassimon.mine.nu with SMTP; 10 Sep 2009 20:06:28 -0000 From: "Tom Cassimon" To: References: <3ED0C0B657094C54A27DAD4E1998B715@Travelmate> <61b5d9410909101148s4c1c71bdv777cbc559342bf4c@mail.gmail.com> <768F0D1811A04965B9A1485E90526F68@Travelmate> <200909101548.13589.dkulp@apache.org> In-Reply-To: <200909101548.13589.dkulp@apache.org> Subject: RE: Problem with primary key in Persisted object list Date: Thu, 10 Sep 2009 22:06:28 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcoyT6Z1ZA8q+spKRjebDjXqHxf/BwAAffdQ X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6002.18005 X-Virus-Scanned: clamav-milter 0.95.2 at lrelay01.edpnet.net X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on lrelay01.edpnet.net X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.2.5 Yes, It does have those methods: =============================== public Long getId() { return id; } public void setId(Long id) { this.id = id; } =============================== One other thing, I also have @OneToOne relationships in the same Object, and they have the Id fields filled in. The problem only appears in @OneToMany relations. Tom -----Oorspronkelijk bericht----- Van: Daniel Kulp [mailto:dkulp@apache.org] Verzonden: donderdag 10 september 2009 21:48 Aan: dev@cxf.apache.org CC: Tom Cassimon Onderwerp: Re: Problem with primary key in Persisted object list Does the "id" field have public getter and setter methods? Without those, it wouldn't get serialized. Dan On Thu September 10 2009 3:19:12 pm Tom Cassimon wrote: > Hi, > > I'm using the newest version 2.2.3. > > The First problem I noticed is when using @OneToMany relationships > in entity classes I do not get the Id (on client side). > > Example class: > > === Part of Patient.java === > > . > . > . > @JoinTable(name = "patient_document", joinColumns = {@JoinColumn(name = > "patientId")}, inverseJoinColumns = {@JoinColumn(name = "documentId")}) > @OneToMany(fetch=FetchType.LAZY) > private List documentList; > . > > ============================ > > === Part of Document.java === > > @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; > . > . > . > > ============================= > > When I check on the server side, the id field is filled in > with the id from the database. But when I check on the client > side the id is "null". This poses a problem when I submit the > Patient object back to the server. The First thing is because > the Id fields are "null" it thinks they are new objects. I update > this with 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); > > Maybe I shouldn't do it this way, I'm not really sure this is good > practice. As a result my database gets flooded with duplicate documents > (with blob's in it) because the cleanup of Orphan's doesn't work properly. > But in the first place the documents should not be reinserted every time. > > The second problem appears on client side when I want to remove a document > from a Patient, it always removes the first in the list, because all Id > fields are "null". > > An other question I have is if it is possible to do lazy loading, I mean > with this load the Document instance but without the byte[] (blob) loaded, > I don't know if it is configurable or what is the best practice to > accomplish this. > > -----Oorspronkelijk bericht----- > Van: Benson Margulies [mailto:bimargulies@gmail.com] > Verzonden: donderdag 10 september 2009 20:48 > Aan: dev@cxf.apache.org > Onderwerp: Re: Problem with primary key in Persisted object list > > 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? > -- Daniel Kulp dkulp@apache.org http://www.dankulp.com/blog