我想确保
有测试:
@Test
public void test() {
// create question->answer and save them to db
QuestionUtil.createQuestion("question1", "answer1");
// detaching question from the hibernate session, let user to think and play with entity
Question question1 = Question.find("title", "question1").first();
Question.em().detach(question1);
// user think/edit time ... [1 minute.. 2 minutes.. coffee.. break time.. ]
// user makes some edits in detached question, create new fresh copy (since it's immutable)
Question editingQuestion = new Question.Builder().copy(question1).title("updated question1").build();
editingQuestion.merge();
// get updated Question
Question updatedQuestion = Question.find("title", "question1").first();
assertEquals(updatedQuestion.getTitle(), "updated question1"); // OK
assertTrue(updatedQuestion .getVersion().intValue() == 1); // FAILS here
}
问题。为什么版本不会增加到1(而不是0)?是否有更好的方法来做到这一点?
问题类的负责人在这里:
@Entity
public class Question extends GenericModel {
@Version
private Integer version;
...