• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Horible tiney issue in Hibernate.

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a simple table .. Student.

colums.
student_id and student_name

here is my code.

Student student=new Student();
student.setId("1");
student.setName("asif");

StudentDAO dao=new StudentDAO(); //Hibernate DAO
dao.saveOrUpdate(student);

I am getting the exception ..............
" Batch update row count wrong: 0"

Anybody know wht the is this ?
regards
A.B
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check your id generator part. is unsaved value correct ? is it set to assigned ? if not, then you do not need to set an id.
 
Awais Bajwa
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

HMB


Java CODE



THanks
A.B
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you want to assign an id you must select id generator="assigned".

Please read the Hibernate Reference.

Best Regards

Sebastian
 
Awais Bajwa
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are rite ... and I was wrong. I changed it to "assigned"

still same exception.. and i guess it had nothing to do with, wht u said.

Now here is my exception for your consideration .


 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.

-Praful
[ May 18, 2006: Message edited by: Praful Thakare ]
 
Awais Bajwa
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


Regards
Awais Bajwa
 
Sebastian Hennebrueder
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I just saw something in your mapping.
In your mapping you are using uppercase names. They should be lowercase.

Best Regards

Sebastian
 
Awais Bajwa
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again .. i have tried it using the lower case properties..
but again following is the result.
 
Sebastian Hennebrueder
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
the following did work on my system. You might add your columns step by step.




 
Awais Bajwa
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Regards
Awais Bajwa
[ May 24, 2006: Message edited by: Awais Bajwa ]
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it good your code is working but just for my info

When Sebastian suggested

When you want to assign an id you must select id generator="assigned"


you replied

You are rite ... and I was wrong. I changed it to "assigned"
still same exception.. and i guess it had nothing to do with, wht u said.



are we missing something here?

-Praful
 
Awais Bajwa
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, when I changed to generator="assigned", I should have used
node.save();

I used node.saveOrUpdate(), instead

that was the think that we were missing.

A.B
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
waoo very useful info,Thanks

-Praful
 
Replace the word "snake" with "danger noodle" in all tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic