I have a code which gets the date from Database from which I took year as below code:
Date expiryDate=dataMgr.getDate();
int validity=2;
expiryDate.setYear(expiryDate.getYear() + validity);
// some piece of code
tx.commit();
i am using hibernate to fetch from Database. everything is working fine but the problem is after commiting ….The DB year from which i took the date (dataMgr.getDate()) also gets changed i dont know why ?? can some one clear me out???
For example, form the above code expiryDate:4/21/2012 (from Database). After commiting it gets changed to 4/21/2014 in DB which should not happen??
I haven’t used that corresponding object any where or updating any where ???
help me out
Objects are in
Persistent statein a singletransaction. Moreover, bothexpiryDateanddateMgr.getDateare referring to same object.Instead of getting reference, get clone of object
I am not sure about the syntax, please check that.