Hi All :)
I have a question about updating objects.
In the application some objects require some special management before update, for example when i have to update my Product i have to store also a ProductBck object, that stores some info about Product and other stuff (an externale TicketId etc.).
The application use DAOs.
The ProductService class pseudo-code is like-this:
Code:
class ProductService {
void updateProduct(int ticketId, Product product) {
Product storedProduct = ProductDAO.load();
ProductBck backup = new ProductBck();
ProductBck.setImportantInfo(storedProduct.getImportantInfo());
ProductBck.setTicketId(tickeId);
ProductBckDAO.create(productBck);
ProductDAO.update(product);
}
}
while the client code is similar to this:
Code:
Product product = ProductDAO.load();
product.setImportantInfo(infoObj);
ProductService productService = new ProductService();
productService.update(product);
The DAOs was based on plain JDBC, but now we have replaced all with Hibernate.
But with Hibernate when we can't use this code because when we load the product from the DB in the ProductService we doesn't load the product actually on DB but the product already modified by the client code.
There is some workaround to avoid this? There is a good solution that doesn't change the ProductService interface?
Thanks :)