On 16/04/13 19:10, Tim Pigden wrote:
> I have a problem I'm not sure the best way to model and it doesn't
> seem to match your use cases.
> I have a js client that expects an int id on the data.
> The client will create new records and wants the int id back with the
> persisted record.
> Subsequently an edit in the grid will send that record (or another)
> back with the the int id. I will then parse the passed in json
> complete with an id field and will want to save the update.
So if I understand correctly you won't know what to do with the
"updated" id and how to update the user?
Seems like an entity with a SurrogateIntId (autogenerated) will do,i.e.
say you want to have a use case with a User domain class:
js save a new User => json data without id (or with a dummy id) => val
stored=mapperDao.insert(UserEntity,new User(name))
Now stored is a User with SurrogateIntId and you can send back the id to
the javascript.
stored.id contains the autogenerated id.
for the update:
val u=mapperDao.select(UserEntity,id) (
u.id contains the id) => send via
json => javascript render the edit user form =>
=> user submits => { user { name:"Kostas" , id:50 } } => val
updatedUser=mapperDao.merge(UserEntity,new User(name),id)
Note that merge does a select and then an update at the moment.
Is that what you need?
Cheers
>
> Now if I use surrogateIntId I can't see how I create a record with an
> id from an external source.
> If I use NaturalId I'm not sure the point at which I get the database
> to autogenerate the id for the new record.
>
> This doesn't seem like an unusual use case - just one I've not had before.
>
> What's the recommendation?
>
> Tim
> --
> You received this message because you are subscribed to the Google
> Groups "mapperdao" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
mapperdao+...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>