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,
|