Dave wrote:
On 1/18/07, Mitesh Meswani <[EMAIL PROTECTED]> wrote:
> if(object.id != null)
>   update()
> else
>   save()

This would be true if the id is generated as is the case with Roller.
For objects where id is user supplied, above algorithm can not be used.
Thats the reason some frameworks (for example JPA) does not provide
equivalent of saveOrUpdate() method.

Yes, that is true and it is the case with the property object, whose
ID is the name property.

And, we can't rely on object.id because we don't know which field is
the id. So, for JPA you'd have to do something like this in the store
method:

       EntityManager em = getEntityManager(true);
       if (!em.contains(obj)) {
           // If entity is not managed we can assume it is new
           em.persist(obj);
       }
       return obj;


I agree. I think the example above is a very appropriate way to deal with scenarios for user managed pojo ids like the PropertyData class.

-- Allen



- Dave

Reply via email to