Post your hbm file. My wild guess is that you might have specified an unsaved value as 0 or -1 for the id, and in your code you are setting the id as 1 and as a result Hibernate is issuing an update instead of insert statement.
hi guys ! THanks for your replies.. well, I used Student entity as an example. actually i m a Node business objects.. and folliwing is its HBM and java code that causing this exception... hope it will help you Hibernate gurus to find an answer
When you want to assign an id you must select id generator="assigned".
Please read the Hibernate Reference.
Best Regards
Sebastian
Things get always more complicated as expected.<br />Author of eBook Hibernate 3 Developer Guide by example<br />Tutorials about Hibernate, EJB, Struts, JSF <a href="http://www.laliluna.de" target="_blank" rel="nofollow">www.laliluna.de</a>
Is this new row your trying to insert? what database are you using? I would suggest use <generator class="org.hibernate.id.IdentityGenerator" /> if your database supports autoincrement (like mysql) and class="sequence" if your databas supports sequence (like oracle) and class="native" if you dont know what your database supports.
and for new rows to be inserted do not set id,let hibernate take care of it.
Thanks for your post. But my requirement is not to use Hibernate generated id, and to assign my own application generated id. How can I accomplish this ?
I am using Mysql, and in one other object i m using class="identity" and it is working fine.
Hello, I just saw something in your mapping. In your mapping you are using uppercase names. They should be lowercase.
Best Regards
Sebastian
Things get always more complicated as expected.<br />Author of eBook Hibernate 3 Developer Guide by example<br />Tutorials about Hibernate, EJB, Struts, JSF <a href="http://www.laliluna.de" target="_blank" rel="nofollow">www.laliluna.de</a>
Hello, the following did work on my system. You might add your columns step by step.
Things get always more complicated as expected.<br />Author of eBook Hibernate 3 Developer Guide by example<br />Tutorials about Hibernate, EJB, Struts, JSF <a href="http://www.laliluna.de" target="_blank" rel="nofollow">www.laliluna.de</a>
Sebasistian, Thanks a lot for your coding example, and that coding example points to a fairly simple mistake I made. I corrected it and my problem has been resolved.
I want to write the soloution of my issue , so that all readers get this information.
I used <generator class="assigned" /> for my identity.
and then I used node.saveOrUpdate(node); So hibernate tried to update that node, (in saveOrUpdate() hibernate always tries to update that record if the id exists.)
when Hibernate tries to update the recorde there is no record already exists in the database, so it throws exception
saveOrUpdate() function wud hav worked if i wud use
for verification you may use saveOrUpdate() in your and you will get the same exception above.