Bug 346 : ENHANCEMENT - Add "updateNullProperties" option for stateless update
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.7.2
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
14/12/2010
Updated 
14/12/2010
Type 
Bug
 
Attachments 
No attachments

What this does is allow the developer to control how nulls are treated by default for stateless updates (when you don't explicitly specify which properties are to be updated).

/**
         * Force an update additionally specifying whether to
         * 'deleteMissingChildren' when the update cascades to a OneToMany or
         * ManyToMany.
         * <p>
         * By default the deleteMissingChildren is true and it is assumed that when
         * cascade saving a O2M or M2M relationship that the relationship is 'fully
         * loaded' and any child beans that are no longer on the relationship will
         * be deleted.
         * </p>
         * <p>
         * You can use this method to FORCE an update to occur (even on a bean that
         * has not been fetched but say built from JSON or XML). When
         * {@link EbeanServer#save(Object)} is used Ebean determines whether to use
         * an insert or an update based on the state of the bean. Using this method
         * will force an update to occur.
         * </p>
         * <p>
         * It is expected that this method is most useful in stateless REST services
         * or web applications where you have the values you wish to update but no
         * existing bean.
         * </p>
         * 
         * @param bean
         *            the bean to update
         * @param updateProps
         *            optionally you can specify the properties to update (can be
         *            null).
         * @param t
         *            optionally you can specify the transaction to use (can be
         *            null).
         * @param deleteMissingChildren
         *            specify false if you do not want 'missing children' of a
         *            OneToMany or ManyToMany to be automatically deleted.
         * @param updateNullProperties
         *            specify true if by default you want properties with null
         *            values to be included in the update and false if those
         *            properties should be treated as 'unloaded' and excluded from
         *            the update. This only takes effect if the updateProps is null.
         */
        public void update(Object bean, Set<String> updateProps, Transaction t, boolean deleteMissingChildren, boolean updateNullProperties);
 
Rob 14 Dec 09:24
As an example:

As a code example:

EbeanServer server = Ebean.getServer(null);

EBasic e = new EBasic();
e.setName("something");
e.setStatus(Status.NEW);
e.setDescription("wow");

// insert a row
server.save(e);
                

EBasic updateName = new EBasic();
updateName.setId(e.getId());
updateName.setName("justName");


// update just the name (non-null properties only)
server.update(updateName, null, null, false, false);

EBasic updateAll = new EBasic();
updateAll.setId(e.getId());
updateAll.setName("updAllProps");

// update all the properties
server.update(updateAll, null, null, false, true);

Rob 14 Dec 09:39
Also note:

Also note you can configure the default behaviour for with properties:

example:

ebean.defaultUpdateNullProperties=true
ebean.defaultDeleteMissingChildren=true

So you might set these as the defaults when using GWT assuming your beans are fully populated (not partially loaded).

Rob 14 Dec 09:57
Fixed in HEAD

Fixed in HEAD.

woResponse

Upload a file