Hi
Version Number gets incremented automatically for scenario1.
Scenario 1:
session = new Configuration().configure("testhibernate.cfg.xml").buildSessionFactory().openSession();
Case loanCase= (Case)session.createCriteria(Case.class) .add(Expression.eq("id", caseId)).uniqueResult(); //here, loanCase.getVersion() = 1
List caseTasks = session.createQuery(HQL_FETCH_CASETASKS).list(); //here, loanCase.getVersion() = 1
loanCase.setCaseTasks(new HashSet(caseTasks)); //to remove duplicates
//here, loanCase.getVersion() = 1
Set borrowers = new HashSet(session.createCriteria(AotBorrower.class) .add(Expression.eq("loan.loanNumber","100").list());
//here, loanCase.getVersion() = 2
loanCase.getLoan().setBorrowers(borrowers);
Question:
Why version gets automatically updated, without firing any UPDATE SQL?
Scenario 2
session = new Configuration().configure("testhibernate.cfg.xml").buildSessionFactory().openSession();
Case loanCase= (Case)session.createCriteria(Case.class) .add(Expression.eq("id", caseId)).uniqueResult(); //here, loanCase.getVersion() = 1
List caseTasks = session.createQuery(HQL_FETCH_CASETASKS).list();//here, loanCase.getVersion() = 1
Set borrowers = new HashSet(session.createCriteria(AotBorrower.class) .add(Expression.eq("loan.loanNumber","100").list());
//here, loanCase.getVersion() = 1
loanCase.setCaseTasks(new HashSet(caseTasks)); //to remove duplicates //here, loanCase.getVersion() = 1
loanCase.getLoan().setBorrowers(borrowers);//here, loanCase.getVersion() = 1
Question:
Here, Why version doesn't get incremented?
All answers will be appreciated.
Thanks,
Ganesh.A
|