I have a class:
@Name("foo")
@Scope(ScopeType.CONVERSATION)
public class Foo {
@In
Session session;
@In
private Conversation conversation;
@RequestParameter
Long barId;
/* outjected fields */
@Out
Bar bar;
/* some attributes and methods */
public void start() {
/* some initializations */
this.bar = (Bar) session.get(Bar.class, barId);
}
public void end() {
/* some actions involving bar and bar.getBaz() */
conversation.end();
}
}
The method start() is called at the beginning of the conversation and initializes the attribute bar (Bar is some entity class). Then, bar has an attribute baz which is also an entity.
During a conversation, it might happen that some other user modifies the baz object related to our bar. Then, when end() is called, bar.getBaz() returns the old (unmodified) version of baz, and, moreover, overwrites it to the database.
I tried to get the modified state of baz in the end() method using session.flush(), session.merge(bar), session.merge(bar.getBaz()), but nothing works. How can I avoid pollution in the database?