[jboss-user] [JBoss Seam] - Re: EntityQuery.refresh() doesn't clear the result list??

ASavitsky do-not-reply at jboss.com
Fri Jul 20 10:16:22 EDT 2007


Indeed, it does :(

Tracing code in ManagedEntityIdentityInterceptor:

	private static final Log log = LogFactory.getLog(ManagedEntityIdentityInterceptor.class);
  | 	private void getFromWrapper(Object bean, Field field, Object dataModel)
  | 			throws Exception {
  | 		Object value = Contexts.getConversationContext().get(getFieldId(field));
  | 		if (value != null) {
  | 			if (dataModel == null) {
  | 				if (field.getName().equals("resultList"))
  | 					log.warn("getFromWrapper: "
  | 							+ bean.getClass().getSimpleName() + "."
  | 							+ field.getName() + " = " + value);
  | 				Reflections.set(field, bean, value);
  | 			} else {
  | 				setWrappedData(dataModel, value);
  | 			}
  | 		}
  | 	}
  | 	private void saveWrapper(Object bean, Field field, Object dataModel,
  | 			Object value) throws Exception {
  | 		if (field.getName().equals("resultList"))
  | 			log.warn("saveWrapper: conversation." + getFieldId(field) + " = "
  | 					+ value);
  | 		Contexts.getConversationContext().set(getFieldId(field), value);
  | 		if (dataModel == null) {
  | 			if (field.getName().equals("resultList"))
  | 				log.warn("saveWrapper: " + bean.getClass().getSimpleName()
  | 						+ "." + field.getName() + " = null");
  | 			Reflections.set(field, bean, null);
  | 		} else {
  | 			setWrappedData(dataModel, null);
  | 		}
  | 	}
  | 

Tracing in EntityQuery:
	private void initResultList() {
  | 		if (getEjbql() != null && getEjbql().startsWith("FROM Account")) {
  | 			log.warn("Entered initResultList: hashcode " + this.hashCode()
  | 					+ ", list = " + resultList);
  | 		}
  | 		if (resultList == null) {
  | 			javax.persistence.Query query = createQuery();
  | 			resultList = query == null ? null : query.getResultList();
  | 		}
  | 		if (getEjbql() != null && getEjbql().startsWith("FROM Account")) {
  | 			log.warn("Exited initResultList: hashcode " + this.hashCode()
  | 					+ ", list = " + resultList);
  | 		}
  | 	}
  | 	@Transactional
  | 	@Override
  | 	public List getResultList() {
  | 		if (getEjbql() != null && getEjbql().startsWith("FROM Account")) {
  | 			log.warn("Entered getResultList: hashcode " + this.hashCode()
  | 					+ ", list = " + resultList);
  | 		}
  | 		if (isAnyParameterDirty()) {
  | 			refresh();
  | 		}
  | 		initResultList();
  | 		try {
  | 			return truncResultList(resultList);
  | 		} finally {
  | 			if (getEjbql() != null && getEjbql().startsWith("FROM Account")) {
  | 				log.warn("Exited getResultList: hashcode " + this.hashCode()
  | 						+ ", list = " + resultList);
  | 			}
  | 		}
  | 	}
  | 	@Override
  | 	public void refresh() {
  | 		if (getEjbql() != null && getEjbql().startsWith("FROM Account")) {
  | 			log.warn("Entered refresh: hashcode " + this.hashCode()
  | 					+ ", list = " + resultList);
  | 		}
  | 		super.refresh();
  | 		resultCount = null;
  | 		resultList = null;
  | 		singleResult = null;
  | 		if (getEjbql() != null && getEjbql().startsWith("FROM Account")) {
  | 			log.warn("Exited refresh: hashcode " + this.hashCode()
  | 					+ ", list = " + resultList);
  | 		}
  | 	}
  | 

Tracing in AccountController (my code):
	@Transactional
  | 	public void save() {
  | 		log.warn("save: before persist");
  | 		em.persist(selectedAccount);
  | 		log.warn("save: before flush");
  | 		em.flush();
  | 		selectedAccount = null;
  | 		log.warn("save: before refresh");
  | 		userAccounts.refresh();
  | 		log.warn("save: after refresh");
  | 	}
  | 

Log output on new record insert (resultList is supposed to go from one item to two):
WARN  [com.tdam.ptss.controller.AccountController] - save: before persist  
  | Hibernate: select SEQ_ACCOUNT.nextval from dual
  | WARN  [com.tdam.ptss.controller.AccountController] - save: before flush  
  | Hibernate: insert into Account (CREATED_BY, CREATED_ON, MODIFIED_BY, MODIFIED_ON, ACCOUNT_NUMBER, closed, DEALER_NAME, discretionary, FAMILY_EXEMPTION, NAME_ON_STATEMENT, USER_ID, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  | WARN  [com.tdam.ptss.controller.AccountController] - save: before refresh  
  | WARN  [org.jboss.seam.persistence.ManagedEntityIdentityInterceptor] - getFromWrapper: EntityQuery.resultList = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Entered refresh: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Exited refresh: hashcode 27469166, list = null  
  | WARN  [com.tdam.ptss.controller.AccountController] - save: after refresh  
  | WARN  [org.jboss.seam.persistence.ManagedEntityIdentityInterceptor] - getFromWrapper: EntityQuery.resultList = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Entered getResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Entered initResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Exited initResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Exited getResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.persistence.ManagedEntityIdentityInterceptor] - saveWrapper: conversation.userAccounts.resultList = [Account[87]]  
  | WARN  [org.jboss.seam.persistence.ManagedEntityIdentityInterceptor] - saveWrapper: EntityQuery.resultList = null  
  | WARN  [org.jboss.seam.persistence.ManagedEntityIdentityInterceptor] - getFromWrapper: EntityQuery.resultList = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Entered getResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Entered initResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Exited initResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.framework.EntityQuery] - Exited getResultList: hashcode 27469166, list = [Account[87]]  
  | WARN  [org.jboss.seam.persistence.ManagedEntityIdentityInterceptor] - saveWrapper: conversation.userAccounts.resultList = [Account[87]]  
  | WARN  [org.jboss.seam.persistence.ManagedEntityIdentityInterceptor] - saveWrapper: EntityQuery.resultList = null  
  | 

Indeed, it does gets reset to old value right after I try to set it to null, and, as it uses reflection, it's no wonder why debugger wasn't catching it :(.

Now, is that considered to be the normal behavior (in which case - are there any ways to disable this interception?), or is this a bug (in which case I'll submit it to JIRA)?

Thanks,

Alex

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4066216#4066216

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4066216



More information about the jboss-user mailing list