You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Vorius <tl...@gmail.com> on 2008/08/27 21:44:17 UTC

Need some help getting dynamic queries working

I am trying to use dynamic queries for the first time and I am really
confused as to why I am getting an error.

In my XML I have this:

<typeAlias alias="TaskFilter" type="com.test.TaskFilter"/>

	<select id="getTasksFiltered" parameterClass="TaskFilter"
resultMap="TaskMap">   
		SELECT * FROM tasks      
  	<dynamic prepend="WHERE">		  
		  <isNotEqual property="priority" compareValue="0" prepend="AND">
		    priority = #priority#
		  </isNotEqual>
		</dynamic> 
		order by due_date desc         
	</select>  

TaskFilter is a public class with following members:

public class TaskFilter {
	int priority = 0;

	public int getPriority() {
		return priority;
	}
	public void setPriority(int priority) {
		this.priority = priority;
	}
}

and I try to execute this as follows:

TaskFilter taskFilter = new TaskFilter();
tasks = sqlMap.queryForList("getTasksFiltered");

It is failing with the following error:

com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/test/xml/Tasks.xml.
--- The error occurred while preparing the mapped statement for execution.
--- Check the getTasksFiltered.
--- Check the parameter map.
--- Cause: java.lang.NullPointerException
     at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
     at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123) 

...

Caused by: java.lang.NullPointerException
     at
com.ibatis.common.beans.ComplexBeanProbe.getProperty(ComplexBeanProbe.java:295)
     at
com.ibatis.common.beans.ComplexBeanProbe.getObject(ComplexBeanProbe.java:199)
     at com.ibatis.common.beans.GenericProbe.getObject(GenericProbe.java:74) 
     ...


So why does this happen? What did I do wrong?

When I remove the whole <dynamic> section from my SQL it will run fine.
-- 
View this message in context: http://www.nabble.com/Need-some-help-getting-dynamic-queries-working-tp19188283p19188283.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Need some help getting dynamic queries working

Posted by Vorius <tl...@gmail.com>.
oh geez, nevermind. I forgot to pass in the paramter class into the
queryForList method. Man I better take a break from all this coding -
starting to make stupid mistakes and taking forever to realize why!
-- 
View this message in context: http://www.nabble.com/Need-some-help-getting-dynamic-queries-working-tp19188283p19188410.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.