Hi,
without your mappings it is hard to say for sure, but I assume monthid is the id-property of your Month-class?
Then there's quite a few queer things about your code....
1.) If you want to get() a certain row and you know its id-attribute you should use
Code:
Month m = session.get(Month.class,2);
to really get the object representing your id-value.
2.) DON'T change the id-attribute of a persistent instance. That is really, really bad. For hibernate different id-values means differente instances. That's why the row doesn't get updated when you change the monthid to a value that isn't in the DB (hibernate will look for a row containing that value and try to update that row).
3.) If you want to update the primary-key-values of any of your tables you should rethink your database-design. primary-keys are for unique identification of any given entity and you wouldn't want to have any entity's identity changed (this is bad style even in pure relational programming). If you need a new Row with monthid = 44 and name="abc" then insert it:
Code:
Month m2 = new Month();
m2.setMonthid(44);
m2.setName("abc);
session.save(m2);
If you no longer need the row with monthid=2 then delete it:
Code:
Month m = session.get(Month.class,2);
session.delete(m);
Regards
piet