Frage

Wenn User ein Unternehmen ist, und ich brauche zu speichern User in Session, wird er am nächsten Anfrage gelöst werden.

AFAIK dort sind nur zwei Methoden, um diese frei stehende Objekte zu behandeln

  1. EntityMerge(session.user) - update DB mit Session-Objekt (unsicher)
  2. session.userID - entityLoadByPK() wieder auf nächste Anfrage (mehr Last)

Sind dies die einzigen zwei Abhilfen? Noch andere Möglichkeiten?

Nach Fortgeschrittene Techniken mit Coldfusion 9 ORM Integration Slide Deck Concurrency mit Methode # 1 wird werfen Fehler, wenn Unternehmen auf Zusammenführung geändert wurde, aber wie ist das sinnvoll? fangen die Ausnahme und die Verwendung Methode # 2?

Wenn EntityReload() benutzen? Ich dachte, es auf die gleiche Weise wie EntityMerge(entity) funktioniert, aber es funktioniert nicht.

Danke!

War es hilfreich?

Lösung

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.

Andere Tipps

I generally just use a lightweight proxy object (containing top-level properties only) in session and only load the full entity as needed in exactly the same use case as you've described. Don't use method #1 unless you really want to burn yourself (experience talking there).

Hibernate sessions are lazy loaded, and do not persist. So while you have the CF object in memory, they're pointing to a Hibernate session which is out of scope, for lack of better terminology. To get back in scope, you basically need to wake it up on your subsequent requests, using something like EntitySave() or EntityLoadByExample()

I do agree that wrapping in a service not only helps you avoid some of these issues, but is overall better architecturally than touching the entity directly.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top