On Thu September 10 2009 5:32:46 pm Tom Cassimon wrote: > 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?
Yea. It's a "Long" which is a object type and is thus possible to be null or not there. That said, I DON'T know why it's not calling getId to figure out if it's there or not. No idea on that one. > 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. Not really. That doesn't work very well with the way soap works. The only way to really do that is to create a second service that would return that byte[] and have the first service send a reference back. Would require quite a bit more coding and such. :-( Dan > > I appreciate the quick response. :-) > > Tom > > -----Oorspronkelijk bericht----- > Van: Daniel Kulp [mailto:[email protected]] > Verzonden: donderdag 10 september 2009 23:10 > Aan: [email protected] > 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:[email protected]] > > Verzonden: donderdag 10 september 2009 22:14 > > Aan: [email protected] > > 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:[email protected]] > > > Verzonden: donderdag 10 september 2009 21:48 > > > Aan: [email protected] > > > 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<Document> 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:[email protected]] > > > > Verzonden: donderdag 10 september 2009 20:48 > > > > Aan: [email protected] > > > > 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 [email protected] http://www.dankulp.com/blog
