nordborg wrote:
So... you probably have loaded a 'B' object and made some changes to it. Then, when you commit the transaction Hibernate will automatically try to store the modified 'B' object, and for some reason that fails. Hard to say why since you have not posted any stack trace or code.
Seeing the traces i have indeed loaded a 'B' object. I have written some useless code but ii causes the error. Basically a retieve an object (wich queries various tables) and make an update without modifiying the onject.
Could it be that the data originally in the DB is not expected to be store that way?, i mean hibernate can retrive it, but since it can't be stored as it was retrived, could it be that there is a restriction in the hibernate configuration that doesn't allow a value and the DB has that same value?.
I'm still confused why if in a session i retrieve an object and store it the same way an update is triggered, As said in post 1 i have executed this same code standalone and in server, the standalone does not trigger the update neither the error, but when executing in server yes, Could it be that another thread is modifying that same object?, an easy way to verify this?
Thanks.
Javi
The code:
private void testUpdate(){
Session hSession = SessionFactory.getSession(0); // This SessionFactory is a custom implementation, it just have several hibernate
//SessionFactory objects, one for each database we connect to. In this example
// only one database is used. The returned Session is a hibernate session.
try{
CEquip equip = null;
Query q2 = hSession.createQuery("from CEquip as ce "
+ " where ce.CEquipType.equiTypeId = 111 "
+ " and ce.equiAlia = :alias")
.setString("alias", "equip");
List<CEquip> lEquips = q2.list();
logger.trace("Number of equips retrived: " + lEquips.size());
if(lEquips.size() > 0){
equip = lEquips.get(0);
}
Transaction t = hSession.beginTransaction();
hSession.update(equip);
t.commit();
}catch (Exception e) {
logger.error("Error updating equip state", e);
}finally{
hSession.close();
}
}
The traces:
Hibernate: select cequip0_.EQUI_ID as EQUI1_20_, cequip0_.EQUI_STAT_ID as EQUI2_20_, cequip0_.EQUI_TYPE_ID as EQUI3_20_, cequip0_.VISIB as VISIB20_, cequip0_.EQUI_ALIA as EQUI5_20_, cequip0_.EQUI_FORE_ID as EQUI6_20_ from C_EQUIP cequip0_ where cequip0_.EQUI_TYPE_ID=111 and cequip0_.EQUI_ALIA=?
Hibernate: select cequipstat0_.EQUI_STAT_ID as EQUI1_21_0_, cequipstat0_.PICT_ID as PICT2_21_0_, cequipstat0_.EQUI_TYPE_ID as EQUI3_21_0_, cequipstat0_.EQUI_STAT_DESC as EQUI4_21_0_, cequipstat0_.EQUI_STAT_FORE_ID as EQUI5_21_0_ from C_EQUIP_STATUS cequipstat0_ where cequipstat0_.EQUI_STAT_ID=?
Hibernate: select cpicts0_.PICT_ID as PICT1_6_0_, cpicts0_.PICT_NAME as PICT2_6_0_, cpicts0_.PICT_PATH as PICT3_6_0_, cpicts0_.PICT_WIDT as PICT4_6_0_, cpicts0_.PICT_HEIG as PICT5_6_0_ from C_PICTS cpicts0_ where cpicts0_.PICT_ID=?
Hibernate: select cequiptype0_.EQUI_TYPE_ID as EQUI1_19_0_, cequiptype0_.PICT_ID as PICT2_19_0_, cequiptype0_.EQUI_TYPE_DESC as EQUI3_19_0_, cequiptype0_.EQUI_TYPE_NAME as EQUI4_19_0_, cequiptype0_.EQUIP_GROUP as EQUIP5_19_0_ from C_EQUIP_TYPE cequiptype0_ where cequiptype0_.EQUI_TYPE_ID=?
Hibernate: select cequipmaps0_.EQUI_ID as EQUI1_1_, cequipmaps0_.MAP_TYPE_ID as MAP2_1_, cequipmaps0_.EQUI_ID as EQUI1_24_0_, cequipmaps0_.MAP_TYPE_ID as MAP2_24_0_, cequipmaps0_.LON as LON24_0_, cequipmaps0_.LATI as LATI24_0_, cequipmaps0_.ZOOM_MAXI as ZOOM5_24_0_, cequipmaps0_.ZOOM_MINI as ZOOM6_24_0_, cequipmaps0_.DRAW_PX_DISP_X as DRAW7_24_0_, cequipmaps0_.DRAW_PX_DISP_Y as DRAW8_24_0_ from C_EQUIP_MAPS cequipmaps0_ where cequipmaps0_.EQUI_ID=?
Hibernate: select maplayers0_.EQUI_TYPE_ID as EQUI1_1_, maplayers0_.MAP_TYPE_ID as MAP2_1_, maplayers0_.EQUI_TYPE_ID as EQUI1_8_0_, maplayers0_.MAP_TYPE_ID as MAP2_8_0_, maplayers0_.INCLUDE as INCLUDE8_0_, maplayers0_.DEFAULT_VISIBLE as DEFAULT4_8_0_ from C_MAP_TYPES_EQUIP_LAYES maplayers0_ where maplayers0_.EQUI_TYPE_ID=?
2012-06-07 09:24:49,812 TRACE [Thread-14] (NotificationsUpdateHandler.java:496) - Number of equips retrived: 1
Hibernate: update C_MAP_TYPES_EQUIP_LAYES set INCLUDE=?, DEFAULT_VISIBLE=? where EQUI_TYPE_ID=? and MAP_TYPE_ID=?
2012-06-07 09:24:49,828 ERROR [Thread-14] (NotificationsUpdateHandler.java:512) - Error updating equip state
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at org.hibernate.type.BooleanType.set(BooleanType.java:36)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:107)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1997)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2371)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2307)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2607)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at xx.xx.xx.xx.xx.testUpdate(NotificationsUpdateHandler.java:508)