This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Normally, if Hibernate is managing the object and you change one property, the update statement only updates that one field.
Now the error you are getting, I don't think it is because of Hibernate trying to update more fields, it sounds more like either database corruption, like the update statement failed because it updated no records cause it couldn't find a record or more. Or even if it is that it could be the mapping is incorrect for the @Id.
Can you post the mapping for that one class that you are trying to update?
OK, well that is really simple mapping there, and it all looks very good. So I guess that is not the problem.
Now the question is what is the update statement that it is running.
In your session factory configuration you can add the property hibernate.show_sql = true so that the statements are displayed iin your console to see the query. The other thing to figure out is what is the constraint that it is violating? What constraints are on the table besides the PK?
In the error message, I see DyeDao, and you are updating DyeCirculation? So, I agree with Mark, it is probably the FK to this table which is missing. Maybe you need a one-to-many and many-to-one mapping added to these 2 classes.
Joined: Jun 25, 2009
Thank you both , for the reply , now the query tells that it tries to update every field generated at console. that is why it generates the constraint violation error as emp_id is FK.
here is query!!!
Try setting not-null="false" for those values in your table which are not required by the database. I can't remember offhand whether it defaults to true or false, but we always set ours, one way or another.
If that doesn't help, please post the code where you are trying to update. It should be something like this:
Also, if you have a Dye class, and Dye.id = die_id in DyeCirculation class, then you should have a foreign key mapping in your DyeCirculation.hbm.xml, or the database will not save/update/cascade in the way you intend. Also, you will not be using Hibernate to the extent of its performance-enhancing abilities.