-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Increment causing problem
PostPosted: Thu Mar 15, 2007 7:51 pm 
Newbie

Joined: Wed May 17, 2006 1:44 pm
Posts: 6
Hi,
I am peristing data into single table in oracle.. I am not using sequence at all. I am using hibernate increment in hbm file.
Code:
public class TestLwot {

   
    public static void main(String[] args) {
        MakeLwotObj makeLwotObj= new MakeLwotObj ();
        LWOTDao lwotDao = new LWOTDaoImpl();
        lwotDao.persistLWOTPatient(makeLwotObj.getLwot());   // IT CALLS SAVE OR UPDATE OF HIBERNATE

// makeLwotObj.getLwot() returns LwotObject.. which does not contain any id.. id field is null..
       
        try {
            Thread.sleep(30 * 1000); 
            lwotDao.persistLWOTPatient(makeLwotObj.getLwot()); // IT CALLS SAVE OR UPDATE OF HIBERNA
TE

        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

   
}   


I am trying to run the SAVEORUPDATE using 2 jvm's then its failing with en exception stating that
Code:
Code:
ORA-00001: unique constraint (DATEAM.SYS_C0039965) violated




Does any body has any ideas why it is doing that






You get this problem when u run this code from different system's or through Different JVM's.

Thanks
Kasinath


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 3:25 am 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Use sequence for the purpose. That would solve the issue.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 6:31 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
The hibernate-doc has the following to say about increment:
Quote:
generates identifiers of type long, short or int that are unique only when no other process is inserting data
into the same table. Do not use in a cluster.


So you clearly can't use increment from two VMs, we even had problems using it with two parallel threads.
In this scenario have to use DB-generated keys (via sequence, identity or similar) or a hilo-generator.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.