Am I missing something for the update

2003-06-26 Thread cmarcourt
Hi,

update works perfectly well in my application for small modification, says only one 
setter.
Now I've got a big big form (it's an eight step form). I stored its values in a 
session during all the time.
I trace the value for a specific field, this value is right to the end.
But when I call the store() method, it's just like these field are not updated in the 
database.
Here is the java source with the trace.

Say I set the adult capacity to 20.

private void update() {
Collection c = null;
java.util.Iterator it = null;
PersistenceBroker broker = null;
com.hbk.bean.House house = (com.hbk.bean.House) 
super.session.getAttribute(Constant.SESSION_HOUSE);
MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult 
capacity 1 :  + house.getAdultCapacity()); // print 20

if (house!=null) {
try {
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
broker.clearCache();

this.processFinalForm(house);

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 2 
:  + house.getAdultCapacity()); // print 20
house.setModificationDate(new java.util.Date());

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 3 
:  + house.getAdultCapacity()); // print 20

Criteria criteria = new Criteria();
criteria.addEqualTo(id, new Integer(house.getId()));

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 4 
:  + house.getAdultCapacity()); // print 20
QueryByCriteria query = new QueryByCriteria(com.hbk.bean.House.class, 
criteria);

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 5 
:  + house.getAdultCapacity()); // print 20

broker.beginTransaction();

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 6 
:  + house.getAdultCapacity()); // print 20

com.hbk.bean.House toBeEdited = (com.hbk.bean.House) 
broker.getObjectByQuery(query);

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 7 
:  + house.getAdultCapacity()); // print 20

toBeEdited.setAdultCapacity(house.getAdultCapacity());

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 8 
:  + house.getAdultCapacity()); // print 20

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 9 
:  + toBeEdited.getAdultCapacity()); // print 20 (notice the toBeEdited and not the 
house object, I know it's stupid, but I can't believe it )
toBeEdited.setChildCapacity(house.getChildCapacity());
toBeEdited.setCity(house.getCity());
toBeEdited.setCountry(house.getCountry());
toBeEdited.setDisplay(house.isDisplay());
toBeEdited.setDistrict(house.getDistrict());
toBeEdited.setHistoricals(house.getHistoricals());
toBeEdited.setInteriorDescriptions(house.getInteriorDescriptions());
toBeEdited.setInventory(house.getInventory());
toBeEdited.setModificationDate(house.getModificationDate());
toBeEdited.setName(house.getName());
toBeEdited.setNewProduct(house.isNewProduct());
toBeEdited.setOutsideDescriptions(house.getOutsideDescriptions());
//toBeEdited.setOwner(house.getOwner());
//toBeEdited.setPhotos(house.getPhotos());
toBeEdited.setReference(house.getReference());
//toBeEdited.setRooms(house.getRooms());
toBeEdited.setSellPrice(house.getSellPrice());
//toBeEdited.setServices(house.getServices());
toBeEdited.setStreet1(house.getStreet1());
toBeEdited.setStreet2(house.getStreet2());
toBeEdited.setStreet3(house.getStreet3());
toBeEdited.setSurface(house.getSurface());
toBeEdited.setType(house.getType());
toBeEdited.setZipCode(house.getZipCode());

broker.store(toBeEdited);
broker.commitTransaction();

this.processPhotoFile(house);
} catch (org.apache.ojb.broker.PersistenceBrokerException pbe) {

MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).fatal(pbe);
} finally {
broker.clearCache();
broker.close();
}
}
}

Do you see a strange thing in my code ?

Christophe


Re: Am I missing something for the update

2003-06-26 Thread cmarcourt
I found my mistake.
I forgot to set the Id to force an update of the object.

Christophe

 Message du 26/06/03 10:49
 De : cmarcourt [EMAIL PROTECTED]
 A : [EMAIL PROTECTED]
 Copie à : 
 Objet : Am I missing something for the update
 Hi,
 
 update works perfectly well in my application for small modification, says only one 
 setter.
 Now I've got a big big form (it's an eight step form). I stored its values in a 
 session during all the time.
 I trace the value for a specific field, this value is right to the end.
 But when I call the store() method, it's just like these field are not updated in 
 the database.
 Here is the java source with the trace.
 
 Say I set the adult capacity to 20.
 
 private void update() {
 Collection c = null;
 java.util.Iterator it = null;
 PersistenceBroker broker = null;
 com.hbk.bean.House house = (com.hbk.bean.House) 
 super.session.getAttribute(Constant.SESSION_HOUSE);
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult 
 capacity 1 :  + house.getAdultCapacity()); // print 20
 
 if (house!=null) {
 try {
 broker = PersistenceBrokerFactory.defaultPersistenceBroker();
 broker.clearCache();
 
 this.processFinalForm(house);
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 2 :  + house.getAdultCapacity()); // print 20
 house.setModificationDate(new java.util.Date());
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 3 :  + house.getAdultCapacity()); // print 20
 
 Criteria criteria = new Criteria();
 criteria.addEqualTo(id, new Integer(house.getId()));
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 4 :  + house.getAdultCapacity()); // print 20
 QueryByCriteria query = new 
 QueryByCriteria(com.hbk.bean.House.class, criteria);
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 5 :  + house.getAdultCapacity()); // print 20
 
 broker.beginTransaction();
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 6 :  + house.getAdultCapacity()); // print 20
 
 com.hbk.bean.House toBeEdited = (com.hbk.bean.House) 
 broker.getObjectByQuery(query);
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 7 :  + house.getAdultCapacity()); // print 20
 
 toBeEdited.setAdultCapacity(house.getAdultCapacity());
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 8 :  + house.getAdultCapacity()); // print 20
 
 MandarinoLogger.getInstance(Constant.HOUSEBOOKING_LOGGER_NAME).debug(adult capacity 
 9 :  + toBeEdited.getAdultCapacity()); // print 20 (notice the toBeEdited and not 
 the house object, I know it's stupid, but I can't believe it )
 toBeEdited.setChildCapacity(house.getChildCapacity());
 toBeEdited.setCity(house.getCity());
 toBeEdited.setCountry(house.getCountry());
 toBeEdited.setDisplay(house.isDisplay());
 toBeEdited.setDistrict(house.getDistrict());
 toBeEdited.setHistoricals(house.getHistoricals());
 toBeEdited.setInteriorDescriptions(house.getInteriorDescriptions());
 toBeEdited.setInventory(house.getInventory());
 toBeEdited.setModificationDate(house.getModificationDate());
 toBeEdited.setName(house.getName());
 toBeEdited.setNewProduct(house.isNewProduct());
 toBeEdited.setOutsideDescriptions(house.getOutsideDescriptions());
 //toBeEdited.setOwner(house.getOwner());
 //toBeEdited.setPhotos(house.getPhotos());
 toBeEdited.setReference(house.getReference());
 //toBeEdited.setRooms(house.getRooms());
 toBeEdited.setSellPrice(house.getSellPrice());
 //toBeEdited.setServices(house.getServices());
 toBeEdited.setStreet1(house.getStreet1());
 toBeEdited.setStreet2(house.getStreet2());
 toBeEdited.setStreet3(house.getStreet3());
 toBeEdited.setSurface(house.getSurface());
 toBeEdited.setType(house.getType());
 toBeEdited.setZipCode(house.getZipCode());
 
 broker.store(toBeEdited);
 broker.commitTransaction();
 
 this.processPhotoFile(house