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 "Todorovich, Milo" <Mi...@pamperedchef.com> on 2007/01/08 20:52:44 UTC

Lazy loading - can I use any collection, such as java.util.Set, or must I use a java.util.List?

I have an bean that I'm trying to retrieve, and this bean has a
collection (java.util.Set) of other beans that I would like to lazily
load. When I run query I get the following exception:

com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/tpc/ipartner/model/Person.xml.  
--- The error occurred while applying a result map.  
--- Check the Person.PersonResult.  
--- The error happened while setting a property on the result object.  
--- Cause: net.sf.cglib.beans.BulkBeanException:
$java.util.List$$EnhancerByCGLIB$$ab076133
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
WithCallback(GeneralStatement.java:188)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
ForObject(GeneralStatement.java:104)
	at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlM
apExecutorDelegate.java:566)
	at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlM
apExecutorDelegate.java:541)
	at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSes
sionImpl.java:106)
	at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClie
ntImpl.java:83)
	at
com.tpc.ipartner.service.person.PersonServiceIBatis.main(PersonServiceIB
atis.java:50)
Caused by: net.sf.cglib.beans.BulkBeanException:
$java.util.List$$EnhancerByCGLIB$$ab076133
	at
com.tpc.ipartner.model.Person$$BulkBeanByCGLIB$$689fafc7.setPropertyValu
es(<generated>)
	at
com.ibatis.sqlmap.engine.accessplan.EnhancedPropertyAccessPlan.setProper
ties(EnhancedPropertyAccessPlan.java:33)
	at
com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanD
ataExchange.java:112)
	at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectVa
lues(BasicResultMap.java:373)
	at
com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResu
ltObject(RowHandlerCallback.java:64)
	at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor
.java:382)
	at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(Sql
Executor.java:301)
	at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.
java:190)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQu
ery(GeneralStatement.java:205)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
WithCallback(GeneralStatement.java:173)
	... 6 more
Caused by: java.lang.ClassCastException:
$java.util.List$$EnhancerByCGLIB$$ab076133
	... 16 more


This happens before I even try to access the collection. It appears that
setPhones is being called with an enhanced list, as shown in the last
line of the stacktrace.


My bean is defined like this:

public class Person {
   private Integer id;
   private String firstName;
   private String lastName;
   private Set phones = new HashSet();

	. . . 
   public Set getPhones() {
	   return phones;
   }

   public void setPhones(Set phones) {
	   this.phones = phones;
   }
}

The examples -- in "iBATIS in Action" and in the iBATIS-SqlMaps-2_en.pdf
that comes with the downlaod -- all use java.util.List, but do not
explicitly say that the collections must be a List. Is this the case?
When I change my bean to use a List for phones, everything works fine.

Thanks,
Milo-


Re: Lazy loading - can I use any collection, such as java.util.Set, or must I use a java.util.List?

Posted by Carfield Yim <ca...@gmail.com>.
Yeah.... In fact I think Set / SortedSet is more match to list for
relational model

On 1/9/07, Todorovich, Milo <Mi...@pamperedchef.com> wrote:
>
>
>
> I have an bean that I'm trying to retrieve, and this bean has a collection
> (java.util.Set) of other beans that I would like to lazily load. When I run
> query I get the following exception:
>
> com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in
> com/tpc/ipartner/model/Person.xml.
> --- The error occurred while applying a result map.
> --- Check the Person.PersonResult.
> --- The error happened while setting a property on the result object.
> --- Cause: net.sf.cglib.beans.BulkBeanException:
> $java.util.List$$EnhancerByCGLIB$$ab076133
>         at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
>
>         at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
>         at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566)
>         at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)
>         at
> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
>         at
> com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:83)
>         at
> com.tpc.ipartner.service.person.PersonServiceIBatis.main(PersonServiceIBatis.java:50)
> Caused by: net.sf.cglib.beans.BulkBeanException:
> $java.util.List$$EnhancerByCGLIB$$ab076133
>         at
> com.tpc.ipartner.model.Person$$BulkBeanByCGLIB$$689fafc7.setPropertyValues(<generated>)
>         at
> com.ibatis.sqlmap.engine.accessplan.EnhancedPropertyAccessPlan.setProperties(EnhancedPropertyAccessPlan.java:33)
>
>         at
> com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:112)
>         at
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:373)
>         at
> com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64)
>         at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:382)
>         at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:301)
>         at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:190)
>         at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
>         at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
>
>         ... 6 more
> Caused by: java.lang.ClassCastException:
> $java.util.List$$EnhancerByCGLIB$$ab076133
>         ... 16 more
>
>
> This happens before I even try to access the collection. It appears that
> setPhones is being called with an enhanced list, as shown in the last line
> of the stacktrace.
>
>
> My bean is defined like this:
>
> public class Person {
>    private Integer id;
>    private String firstName;
>    private String lastName;
>    private Set phones = new HashSet();
>
>         . . .
>    public Set getPhones() {
>            return phones;
>    }
>
>    public void setPhones(Set phones) {
>            this.phones = phones;
>    }
> }
>
> The examples -- in "iBATIS in Action" and in the iBATIS-SqlMaps-2_en.pdf
> that comes with the downlaod -- all use java.util.List, but do not
> explicitly say that the collections must be a List. Is this the case? When I
> change my bean to use a List for phones, everything works fine.
>
> Thanks,
> Milo-