Search code examples
ormcoldfusioncoldfusion-9

How to work with detached object in CF9?


If User is an entity, and I need to store User in Session, it will be detached on next request.

AFAIK there're only 2 methods to handle these detached objects

  1. EntityMerge(session.user) - update DB with session's object (unsafe)
  2. session.userID - entityLoadByPK() again on next request (more load)

Are these the only 2 workarounds? Any other ways?

According to Advanced Techniques with ColdFusion 9 ORM Integration Slide Deck Concurrency with method #1 will throw error if entity has been changed on merge, but how is this useful? catch the exception and use method #2?

When to use EntityReload()? I thought it works the same way as EntityMerge(entity) but it doesn't.

Thanks!


Solution

  • I tend to only store the ID of the user that is logged in in the session.

    Then I have a UserService.getCurrentUser() facade method that returns that user if I need it.

    That way the user is always current, and never detached.