Why not handle this in your domain objects already?
@Entity
public class Person {
...
@Embedded
private Address address;
...
public Address getAddress() {
if (address == null) {
address = new Address();
}
return address;
}
}
Sven
On 11/30/2012 11:49 PM, Andrew Geery wrote:
I have a Person Hibernate/JPA entity with an @Embedded address object in it:
@Entity
public class Person {
...
@Embedded
private Address address;
...
}
I have a Panel with a Form for editing the Address
(EditAddressFormPanel) and a panel for editing the Person which uses
the Panel for editing (EditPersonFormPanel).
public class EditPersonFormPanel extends Panel {
public EditPersonFormPanel(String cid, IModelPerson model) {
super(cid, model);
// create the person form
Form form = ...
// add the address form panel to it
form.add(new EditAddressFormPanel(address, new
PropertyModelAddress(model, address));
...
}
}
This works if the Person.address field is not null. However, because
of the way that JPA works, the address field will be null if all of
the fields in the class are null. For example, if a Person object was
persisted without an initial address (i.e., address = null). When
this happens,
org.apache.wicket.model.AbstractPropertyModel.getInnermostModelOrObject()
returns null and I ultimately get a WicketRuntimeException: Attempted
to set property value on a null object in PropertyResolver.setValue
because the object is null.
My question is how to deal this this correctly at the model level. I
think IModel.setObject should create a new object if the incoming
object is null and IModel.getObject should return null if no fields
are set on the object to match how JPA/Hibernate handles this.
How do other people handle this problem? Is there a good model to
extend from (maybe something like IWrapModel)? Any examples?
Thanks
Andrew
PS I'm already using EntityModels
(http://wicketinaction.com/2008/09/building-a-smart-entitymodel/)
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org