Re: WicketRuntimeException: Attempted to set property value on a null object
Ah, silly Hibernate ;). AFAICS sooner or later a Wicket component will have to write a value into the embedded address, so obviously it has to be there. You can of course build a specialized model doing some magic here, but at the moment I don't know how that might look like. Sven On 12/01/2012 12:43 AM, Andrew Geery wrote: The problem with doing that is that Hibernate detects that as a change (a null object is not the same as an empty object) and does a database update (see some of the comments on this: https://issues.jboss.org/browse/HIBERNATE-50). Andrew On Fri, Nov 30, 2012 at 5:59 PM, Sven Meier s...@meiers.net wrote: d - 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
WicketRuntimeException: Attempted to set property value on a null object
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
Re: WicketRuntimeException: Attempted to set property value on a null object
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
Re: WicketRuntimeException: Attempted to set property value on a null object
The problem with doing that is that Hibernate detects that as a change (a null object is not the same as an empty object) and does a database update (see some of the comments on this: https://issues.jboss.org/browse/HIBERNATE-50). Andrew On Fri, Nov 30, 2012 at 5:59 PM, Sven Meier s...@meiers.net wrote: d - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org