These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Multi uSers
PostPosted: Sun Apr 01, 2007 2:12 pm 
Newbie

Joined: Sun Apr 01, 2007 2:08 pm
Posts: 4
Hi,

I am very much new to Hibernate.

I found a very strange error in my application.

I am trying to save data in a Oracle table.

When I do this stand alone (1 single user), everything works fine.

When multiple users try to save data in the same tbale almost at the same time, like the QA guys trying to test the save functionality, it fails and throws errors.

Can anyone let me know what could be the reason for this. Is there anything to be done at hibernate end.

Thanks


Top
 Profile  
 
 Post subject: hi
PostPosted: Sun Apr 01, 2007 11:50 pm 
Beginner
Beginner

Joined: Thu Feb 01, 2007 3:08 am
Posts: 20
Kindly paste the exception and hibernate configeration

Regards
Gokul


Top
 Profile  
 
 Post subject: Error
PostPosted: Mon Apr 02, 2007 3:23 am 
Newbie

Joined: Sun Apr 01, 2007 2:08 pm
Posts: 4
Hi,

I have a table with primary key as integer and auto generated
When I try to save into this table, by using getHibernateTenplate.save.... method,

the errro thrown is

One or more records you are trying to insert or update is already present in the database table.

This is kind of wierd becasue the primary key is auto generated and I am passing a null value while saving it. I have also tried to send -1 instead of null.

Still no luck.

Thanks
Jasmina


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 3:50 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
dont pass the value primary key coz it will b autogenerated by hibernate as below:

<class name="com.iflex.fcr.dataSelect.Account" table="TEST">
<id name="id" column="ID" type="integer">
<generator class="native" />
</id>
<!-- will generate primary key id automatically -->
<property name="name" column="NAME" type="string" />
</class>

so u jst passthe other fields and try to save it.

hope it will work,
waiting for ur reply whether it works or not

Regards,
dont forget to give rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 12:52 pm 
Newbie

Joined: Sun Apr 01, 2007 2:08 pm
Posts: 4
I meant to say that I tried to fill the value of id as null in the value object.

The id field has to be there in the object else how will I map it to the database table.

So while saving, when I fill in the object (value object), I do not provide any value to the id. Hence the id in the Value Object goes null while saving.

Thanks
Jasmina


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 4:19 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
for example :

class Account
{
getter setter methods including id
}

Account a;
a.setId() /* no need to set id, hibernate will automatically decide n wil insert it */
a.setName("ABC");
session.save(a);

so ID (primary kye) is not in picutre at all while saving the records,coz it is automatically done by hibernate by:

<id name="id" column="ID" type="integer">
<generator class="native" />
</id>

which will b in ur hbm file.

hope u understant or want more clearance...

Regards


Top
 Profile  
 
 Post subject: Re: Error
PostPosted: Tue Apr 03, 2007 4:50 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
jasmina wrote:
Hi,

I have a table with primary key as integer and auto generated
When I try to save into this table, by using getHibernateTenplate.save.... method,

the errro thrown is

One or more records you are trying to insert or update is already present in the database table.

This is kind of wierd becasue the primary key is auto generated and I am passing a null value while saving it. I have also tried to send -1 instead of null.

Still no luck.

Thanks
Jasmina


What generator-class are you using to generate the id? Posting your mapping-file would help us very musch because we wouldn't have to guess at your configuration.
My guess is that you're using generator="increment" which works fine in a singletreaded environment but will surely fail when running a multithreaded application (because increment isn't threadsafe). You'll have to use something like hilo, native, sequence,.... instead.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.