[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - setParameter: weird query behaviour

mgombocz do-not-reply at jboss.com
Sun Sep 17 17:31:52 EDT 2006


Hi folks, 
I am using Seam, JBoss AS, Facelets, MyFaces and would like to create application-scoped components (lists with salutations, titles etc.) for filling dropdown lists. 
I am doing that by having a SLSB with a @Factory method that initially fills my outjected variable "salutationItems". 
In the @Factory method I call "createQuery": 
Query query = em.createQuery("SELECT new javax.faces.model.SelectItem(s.value, s.label) FROM StringListItem s WHERE s.listType = '
  | SALUTATION' ORDER BY s.label");
  | salutationItems = query.getResultList();In this case everything works fine! 
But, as soon as I want to use "setParameter" instead of the hardcoded Select statement...Query query = em.createQuery("SELECT new javax.faces.model.SelectItem(s.value, s.label) FROM StringListItem s WHERE s.listType = :lType ORDER BY s.label");
  | query.setParameter("lType", "SALUTATION");
  | salutationItems = query.getResultList();	 
...I get the error when I call the JSF page:javax.ejb.EJBTransactionRolledbackException: java.lang.ClassCastException: java.lang.String
  | 	at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
  | 	at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
  | 	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:201)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:6
  | 2)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
  | 	at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
  | 	at $Proxy496.loadSalutations(Unknown Source)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 	at java.lang.reflect.Method.invoke(Method.java:585)
  | 	at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
  | 	at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:32)
  | 	at org.jboss.seam.Component.callComponentMethod(Component.java:1334)
  | 	at org.jboss.seam.Component.getInstanceFromFactory(Component.java:1293)
  | 	at org.jboss.seam.Component.getInstance(Component.java:1260)
  | ...
At the end of a bunch of exception stack traces there is a last log info:
01:18:13,375 INFO  [ConnectionManager] forcing batcher resource cleanup on transaction completion;
  | forgot to close ScrollableResults/Iterator?

I am trying on my own for days now and give up... 
Could anyone of you please help me? 

Thanks! 

PS. Here's the complete code: 
@Stateless
  | @Name("stringLists")
  | public class StringListManager implements StringListManagerLocal {
  | 
  | 	@Logger
  | 	Log log;
  | 
  | 	@PersistenceContext
  | 	private EntityManager em;
  | 
  | 	@Out(scope = ScopeType.APPLICATION)
  | 	private List<SelectItem> salutationItems;
  | 
  | 	@Factory("salutationItems")
  | 	public void loadSalutations() {
  | 		log.info("Start loading salutationItem");
  | 
  | 		Query query = em
  | 				.createQuery("SELECT new javax.faces.model.SelectItem(s.value, s.label) FROM StringListItem s WHERE s.listType = :
  | lType ORDER BY s.label");
  | 		query.setParameter("lType", "SALUTATION");
  | 
  | 		salutationItems = query.getResultList();
  | 
  | 		log.info("End loading salutationItem. Count: "+ salutationItems.size());
  | 	}
  | }
Part of the JSF page: 
  | 		<h:selectOneMenu id="salut">
  | 			<f:selectItems value="#{salutationItems}" />
  | 		</h:selectOneMenu>

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

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



More information about the jboss-user mailing list