-->
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.  [ 1 post ] 
Author Message
 Post subject: mismatched id number
PostPosted: Sat Jun 10, 2006 12:09 pm 
Newbie

Joined: Sat Jun 10, 2006 11:51 am
Posts: 1
Hi all,
We are using a Hibernate 2.1 with Derby DB and one of our customers experience a strange problem.
They save items, and we provide a feature to print an item id.

This is a part of Item.hbm file for item id.
<class
name="Item"
table="ITEM"
>
<id
name="ItemNbr"
type="long"
column="ID"
>
<generator class="vm"/>
</id>


To ptint an item id, we run the following sql:
public long getMaxItemNbr() throws HibernateException{
Session s = getSession();
try{

Long max = (Long)s.createQuery("select max(item.ItemNbr) from Item item").uniqueResult();
if(max==null)
return 0;
return max.longValue() + 1;
}finally{
closeSession(s);
}

}
Then, we capture an item and print the id.
Right after this, we save an item:
public void saveItem(Item item) throws SaveItemException {
try {
ItemDAO.getInstance().save(item);
} catch ( HibernateException e ) {
throw new SaveItemException( "Hibernate Exception caught saving item", e );
}
}

These processes are inside a "while" loop and we finish the loop when ther is no more item.

Problem is that one of our customers see the following printed ids: 1, 1, 2, 3, 4, 5...
Inside their DB, they have correct item is: 1, 2, 3, 4, 5, 6....

It seems item is actually saved one cycle late.

Any helpful tip is appreciated.

Thanks,


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

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.