• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Hibernate Exception

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

Can any one tell me how to solve following Exception in hibernate?

org.hibernate.jdbc.BatchedTooManyRowsAffectedException


So please help me for solving this exception.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the code that caused this? It usually happens when you work on invalid entities (i.e. those without a primary key).
 
Amol Umrani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Session session = null;
Transaction trx = null;

InOutTypes inouttypes = new InOutTypes();

String name = null;


name = (String) this.txtDocType.getText();

try {
session = HibernateUtil.getSession();
trx = session.beginTransaction();

inouttypes.setName(name);

session.save(inouttypes);

trx.commit();
session.close();
} catch (Exception e) {
e.getMessage();
} finally {
if (trx != null) {
trx = null;
}
if (session != null) {
session.clear();
session.close();
session = null;
}
}

return null; //"AddedDocType";

This is the code for inserting value in InOutTypes persistent class.
There are only two fields.
1.inOutTypeId rimary Key
2.Name

So please solve my problem ASAP
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What generation stategy do you use for the id property of your object?
 
Amol Umrani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<id name="inOutTypeId" type="int">
<column name="IN_OUT_TYPE_ID" />
<generator class="assigned" />
</id>
<property name="name" type="string">
<column name="NAME" length="100" not-null="true">
<comment></comment>
</column>
</property>

inOutTypeId is auto incremented field.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


inOutTypeId is auto incremented field.


Not according to your mapping. You are using the assigned strategy, i.e. you need to assign the ID yourself. Try using native.
 
Amol Umrani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But we generate Persistent classes and hbm files by reverse engineering.

that why generator class of inoutTypeId is assigned.

we only use those hbm and orm.

but is it right way to change assigned to native?

I just check it but there is still problem.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using an assigned id generation strategy you will need to assign an id. Simple as that. If you reverse engineering tool has given you something else I'd check the tools documentation, see if you need to do something to properly generate a different strategy.
 
Amol Umrani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i get Exception after change to native.

an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amol Umrani:
Actually i get Exception after change to native.



Check your DDL. Does the table have a primary key? Is it really autoincrement?


an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)


AssertionFailure? Can you show us the stacktrace?
 
Amol Umrani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot...

My problem is solved by changing aasigned to native generator class of inoutTypeId.


can you solve my another problem?

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

This is occured when there is a foreign key is in table which is add to the table using hibernate.


I already try as following...

Users user = new Users();

user.setUserId((Integer)this.dropDown1.getValue());

and by another way...

user.setUserId((Integer.parseInt)(this.dropDown1.getValue());

so can you solve my problem please....
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What type of object does your collection hold? According to the error, it is a String, so this:

will not work.

This:

is not valid java so wont work either.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After changing generator class to native, i already had an |org.hibernate.AssertionFailure: InvocationTargetException|. So how can i fix it.

Thanks
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic