Hi,
I am not sure if this the correct thread for my post. Please redirect me if I'm wrong.
I have the following piece of code, which does not give the result I expected :
GlobalStatus is an hibernate bean that looks like this :Code:... GlobalStatus newGlobalStatus = currentStatusService.computeGlobalStatus(xxx, yyy); GlobalStatus previousGlobalStatus = currentStatusService.getGlobalStatus(zzz); LOGGER.warn("1 newGlobalStatus.getId(): " + newGlobalStatus.getId()); LOGGER.warn("1 previousGlobalStatus.getId(): " + previousGlobalStatus.getId()); if(previousGlobalStatus==null || (previousGlobalStatus.getId()!=newGlobalStatus.getId())) { if(previousGlobalStatus==null ){LOGGER.warn("previousGlobalStatus : null " );} if(previousGlobalStatus!=null && previousGlobalStatus.getId()!=newGlobalStatus.getId()) { LOGGER.warn("previousGlobalStatus.getId()!=newGlobalStatus.getId()" ); } LOGGER.warn("2 previousGlobalStatus.getId() : " + previousGlobalStatus.getId() ); LOGGER.warn("2 newGlobalStatus.getId() : " + newGlobalStatus.getId() ); .... }
The methods currentStatusService.computeGlobalStatus() and currentStatusService.getGlobalStatus() request objects from the database using HQL. Like this :Code:@Entity @Table(name="GLOBAL_STATUS") public class GlobalStatus { private Integer id; ... @Id @GeneratedValue(strategy=GenerationType.AUTO) public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } ... }
When I execute the piece of code I get :Code:public GlobalStatus getByKnownCardholderCurrentStatus( KnownCardholderCurrentStatus knownCardholderCurrentStatus) { StringBuilder stringQuery = new StringBuilder(""); stringQuery.append(" SELECT globalStatus "); stringQuery.append(" FROM KnownCardholderCurrentStatus knownCardholderCurrentStatus "); stringQuery.append(" JOIN knownCardholderCurrentStatus.globalStatus globalStatus "); stringQuery.append(" WHERE knownCardholderCurrentStatus = :knownCardholderCurrentStatus "); Query query = sessionFactory.getCurrentSession().createQuery(stringQuery.toString()); query.setParameter("knownCardholderCurrentStatus", knownCardholderCurrentStatus); return (GlobalStatus) query.uniqueResult(); }
This shouldn't be happening...Code:1 newGlobalStatus.getId(): 130 1 previousGlobalStatus.getId(): 130 previousGlobalStatus.getId()!=newGlobalStatus.getId() 2 previousGlobalStatus.getId() : 130 2 newGlobalStatus.getId() : 130
Am I really tired and I am missing something obvious ? I still don't understand why is this happening. I am suspecting that it is caused by the proxy mechanism of Spring.
Any idea ?
Sylvain


Reply With Quote