Thx but i`m already doing this
i`ll paste the entire code here to see the whole situation:
this is my create method code:
Code:
tx = session.beginTransaction();
rtDTO.setIsHistory("1");
session.update(rtDTO);
tx.commit();
session.evict(rtDTO);
tx = session.beginTransaction();
rtDTO.setIsHistory("0");
// creates a new record in the database with rtDTO
session.save(rtDTO);
connectTraderToProducts(rtDTO);
tx.commit();
In this method when i invoke save() method the id is changed to the
last+1 in the table. But when i invoke the
here is the method "connectTraderToProducts" where i connect many to many association
Code:
List products = (List) rtDTO.getCommonExciseProductMany();
for (int i = 0; i < products.size(); i++) {
Product product = (Product ) products.get(i);
ArrayList existed = new ArrayList(product.getTraders());
/* ------
When i retrieve the traders for this product
the id of the Trader is rolled back to the previous one before
i evict() it from the session and invoke save() method
any idea why this happens?
*/ ---
boolean exist = false;
for (int j = 0; j < existed.size(); j++) {
Trader rt = (Trader) existed.get(j);
if (rt.getId().equals(rtDTO.getId())) {
exist = true;
}
}
if (!exist) {
product.getTraders().add(rtDTO);
}
}