Return-Path: Delivered-To: apmail-cxf-dev-archive@www.apache.org Received: (qmail 47176 invoked from network); 10 Sep 2009 21:33:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Sep 2009 21:33:22 -0000 Received: (qmail 61122 invoked by uid 500); 10 Sep 2009 21:33:21 -0000 Delivered-To: apmail-cxf-dev-archive@cxf.apache.org Received: (qmail 61053 invoked by uid 500); 10 Sep 2009 21:33:21 -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 61041 invoked by uid 99); 10 Sep 2009 21:33:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 21:33:21 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.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 21:33:09 +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 n8ALWl8Q010587 for ; Thu, 10 Sep 2009 23:32:47 +0200 Received: (qmail 25550 invoked from network); 10 Sep 2009 21:32:47 -0000 Received: from travelmate.lan (HELO Travelmate) (192.168.182.116) by cassimon.mine.nu with SMTP; 10 Sep 2009 21:32:47 -0000 From: "Tom Cassimon" To: References: <3ED0C0B657094C54A27DAD4E1998B715@Travelmate> <200909101613.55788.dkulp@apache.org> <200909101710.10585.dkulp@apache.org> In-Reply-To: <200909101710.10585.dkulp@apache.org> Subject: RE: Problem with primary key in Persisted object list Date: Thu, 10 Sep 2009 23:32:46 +0200 Message-ID: <2F99ACA2CDA2433EBA389E5C8B5C7AA6@Travelmate> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcoyWy/e5Iky1KdzR1y3T4JPvra12AAAd8WQ 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 Hi, The annotation @XmlElement(required=true) seems to fix it, the Id field is now setted using the setter. Strange, I can't check it out further right now. Any idea why this could solve the problem? Does JAXB see it as an optional property somehow? But anyway thanks for the solution, this weekend I'm on holiday so I can't test it, but I will do some more testing next week and keep you posted. Do you have a good strategy to exclude a large byte[] for being automatically loaded by the client, but only load it when the getter is called? Some sort of lazy loading of the variable. I appreciate the quick response. :-) Tom -----Oorspronkelijk bericht----- Van: Daniel Kulp [mailto:dkulp@apache.org] Verzonden: donderdag 10 september 2009 23:10 Aan: dev@cxf.apache.org CC: Tom Cassimon Onderwerp: Re: Problem with primary key in Persisted object list On Thu September 10 2009 4:24:07 pm Tom Cassimon wrote: > Hi, > > the method doesn't get called. Is there maybe any logging I can enable to > check why it isn't called? I use log4j. No idea. This would be way down in JAXB runtime someplace. I wonder if you add an @XmlElement annotation onto the getter method with things like required=true and possibly a name other than "id" (so it doesn't get confused with an xml:id) or similar if jaxb would call it. Then again, I don't know why it would have worked in the OneToOne case then. You could also try configuring the various JAXB event handler things on the jaxb databinding. It's possible that an event handler is getting some sort of error condition and then returning a "continue" which tells jaxb to ignore the error. Dan > > Tom > > -----Oorspronkelijk bericht----- > Van: Daniel Kulp [mailto:dkulp@apache.org] > Verzonden: donderdag 10 september 2009 22:14 > Aan: dev@cxf.apache.org > CC: Tom Cassimon > Onderwerp: Re: Problem with primary key in Persisted object list > > > Strange. All I can suggest then is to set a breakpoint in the getId > method > > to make sure it's called during writing. > > Dan > > On Thu September 10 2009 4:06:28 pm Tom Cassimon wrote: > > 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