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 Brandon Goodin <br...@gmail.com> on 2005/04/01 03:09:02 UTC

Re: ClassCastException building SqlMap instance

What are you using for your datasource?

Brandon


On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com> wrote:
> I've written some classes that employ the iBatis framework for data access.
> All patterns used are identical to the iBatis JPetStore example (DaoManager,
> SqlMaps, a "service" class which abstracts all this, etc.)
> 
> These classes work great when accessed from a Tomcat web application.  But I
> ran into problems using these classes in a custom Realm for Tomcat.  These
> are the errors I'm getting when the class loader initializes everything on
> Tomcat startup:
> 
> Caused by: java.lang.RuntimeException: Could not initialize BrokerDaoConfig.
> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was an
> error while building the SqlMap instance.
> --- The error occurred in the SQL Map Configuration file.
> --- The error occurred while configuring the data source.
> --- Check the data source type or class.
> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> java.lang.ClassCastException
> 
> Can anyone shed some light on the ClassCastException?  I Googled but found
> no references to this exception in this context.
> 
> As I mentioned, my classes work when all iBatis (and related) jars are under
> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to use
> the classes in a custom Realm implementation, I've placed all the jars under
> server/lib directory - that is the only difference between a working and
> non-working scenario.
> 
> Thanks for all your help,
> 
> -Sasha Borodin
> 
>

Re: ClassCastException building SqlMap instance

Posted by Kris Jenkins <kr...@yahoo.co.uk>.
John Fereira wrote:

> At 12:55 PM 4/1/2005 +0100, Kris Jenkins wrote:
>
>>> If you're looking for the library which contains the offending class 
>>> here's a trick I use.  Go into the directories that your classloader 
>>> will use to find jar files (common/lib, server/lib, etc).  If you're 
>>> using using some version of unix run the bourne shell (/bin/sh) or 
>>> bash and execute the following:
>>>
>>> for name in *.jar
>>> do
>>>    echo LIBRARY: $name >> classlist
>>>    jar tvf $name >> classlist
>>> done
>>>
>>>
>>> Now you can look in the classlist file and search for the class name 
>>> that is causing the casting exception.  Scroll up until you find the 
>>> name of the class which contains it.
>>> John Fereira
>>> jaf30@cornell.edu
>>> Ithaca, NY
>>
>>
>> As it's Friday, anyone for a game of *nix golf?
>>
>>    find . -name \*.jar -print -exec jar tvf {} \;
>
>
> That would work too, although to be useful you'd want to pipe the 
> output to a file for subsequent class name lookups.

Okay, give me par 52:

find . -name \*.jar -print -exec jar tvf {} \;|vi -

:-)


Re: ClassCastException building SqlMap instance

Posted by John Fereira <ja...@cornell.edu>.
At 12:55 PM 4/1/2005 +0100, Kris Jenkins wrote:

>>If you're looking for the library which contains the offending class 
>>here's a trick I use.  Go into the directories that your classloader will 
>>use to find jar files (common/lib, server/lib, etc).  If you're using 
>>using some version of unix run the bourne shell (/bin/sh) or bash and 
>>execute the following:
>>
>>for name in *.jar
>>do
>>    echo LIBRARY: $name >> classlist
>>    jar tvf $name >> classlist
>>done
>>
>>
>>Now you can look in the classlist file and search for the class name that 
>>is causing the casting exception.  Scroll up until you find the name of 
>>the class which contains it.
>>John Fereira
>>jaf30@cornell.edu
>>Ithaca, NY
>
>As it's Friday, anyone for a game of *nix golf?
>
>    find . -name \*.jar -print -exec jar tvf {} \;

That would work too, although to be useful you'd want to pipe the output to 
a file for subsequent class name lookups.


Re: ClassCastException building SqlMap instance

Posted by Kris Jenkins <kr...@yahoo.co.uk>.
> If you're looking for the library which contains the offending class 
> here's a trick I use.  Go into the directories that your classloader 
> will use to find jar files (common/lib, server/lib, etc).  If you're 
> using using some version of unix run the bourne shell (/bin/sh) or 
> bash and execute the following:
>
> for name in *.jar
> do
>    echo LIBRARY: $name >> classlist
>    jar tvf $name >> classlist
> done
>
>
> Now you can look in the classlist file and search for the class name 
> that is causing the casting exception.  Scroll up until you find the 
> name of the class which contains it.
> John Fereira
> jaf30@cornell.edu
> Ithaca, NY

As it's Friday, anyone for a game of *nix golf?

    find . -name \*.jar -print -exec jar tvf {} \;

I make that par 47. :-)

Kris

-- 
Kris Jenkins
Email:  kris@jenkster.com
Blog:   http://cafe.jenkster.com/
Wiki:   http://wiki.jenkster.com/



Re: ClassCastException building SqlMap instance

Posted by John Fereira <ja...@cornell.edu>.
At 07:16 PM 3/31/2005 -0600, Sasha Borodin wrote:
>Excerpt from sql-map-config.xml:
>
>     <dataSource type="DBCP">
>         <property name="JDBC.Driver"
>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
>
>
>The error persists whether or not I place the commons-dbcp, commons-pool,
>commons-collections, and the jdbc driver jars in server/lib.

In documentation I have read regarding using commons-dbcp it suggest 
putting the jar files in $TOMCAT_HOME/common/lib (not server/lib) *and* 
that you do not have your jdbc driver in the context lib directory 
(TOMCAT_HOME/webapps/CONTEXTNAME/WEB-INF/lib).

If you're looking for the library which contains the offending class here's 
a trick I use.  Go into the directories that your classloader will use to 
find jar files (common/lib, server/lib, etc).  If you're using using some 
version of unix run the bourne shell (/bin/sh) or bash and execute the 
following:

for name in *.jar
do
    echo LIBRARY: $name >> classlist
    jar tvf $name >> classlist
done


Now you can look in the classlist file and search for the class name that 
is causing the casting exception.  Scroll up until you find the name of the 
class which contains it.
John Fereira
jaf30@cornell.edu
Ithaca, NY


Re: ClassCastException building SqlMap instance

Posted by Brandon Goodin <br...@gmail.com>.
What is the full exception?

Brandon


On Thu, 31 Mar 2005 20:21:09 -0600, Sasha Borodin <sa...@whoissasha.com> wrote:
> Yes, I have ibatis-common-2.jar on the classpath.
> 
> I've tested my classes from within IntelliJ Idea, and implemented them
> successfully in a number of web applications.  I'm not sure how to go about
> debugging this particular environment, however.
> 
> The jars are all located in $CATALINA_HOME/server/lib, instead of the
> WEB-INF/lib directory; that is the only difference that I can see - which
> makes me think it's some kind of a conflict with existing jars, or there's a
> necessary jar that hasn't yet been loaded by the classloader before the
> ibatis classes are initialized in this scenario.
> 
> If anyone has used iBatis in this context (tomcat realm implementations) and
> is familiar with any nuances, please let me know.  Also, if you have a
> suggestion for debugging WHAT particular statements or code cause the
> ClassCastException, that would also be very helpful to troubleshooting this.
> 
> >>>> --- Check the data source type or class.
> >>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> >>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> >>>> java.lang.ClassCastException
> 
> Thanks again.
> 
> -Sasha Borodin
> 
> 
> > From: Brandon Goodin <br...@gmail.com>
> > Reply-To: <ib...@incubator.apache.org>
> > Date: Thu, 31 Mar 2005 19:04:39 -0700
> > To: <ib...@incubator.apache.org>
> > Subject: Re: ClassCastException building SqlMap instance
> >
> > do you have the ibatis-common.jar on your classpath?
> >
> > If i were you i would put this in a debugger.
> >
> > Brandon
> >
> > On Thu, 31 Mar 2005 19:16:50 -0600, Sasha Borodin <sa...@whoissasha.com>
> > wrote:
> >> Excerpt from sql-map-config.xml:
> >>
> >>     <dataSource type="DBCP">
> >>         <property name="JDBC.Driver"
> >>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
> >>
> >> The error persists whether or not I place the commons-dbcp, commons-pool,
> >> commons-collections, and the jdbc driver jars in server/lib.
> >>
> >> Thanks for looking at this.
> >>
> >> -Sasha
> >>
> >>> From: Brandon Goodin <br...@gmail.com>
> >>> Reply-To: <ib...@incubator.apache.org>
> >>> Date: Thu, 31 Mar 2005 18:09:02 -0700
> >>> To: <ib...@incubator.apache.org>
> >>> Subject: Re: ClassCastException building SqlMap instance
> >>>
> >>> What are you using for your datasource?
> >>>
> >>> Brandon
> >>>
> >>>
> >>> On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
> >>> wrote:
> >>>> I've written some classes that employ the iBatis framework for data access.
> >>>> All patterns used are identical to the iBatis JPetStore example
> >>>> (DaoManager,
> >>>> SqlMaps, a "service" class which abstracts all this, etc.)
> >>>>
> >>>> These classes work great when accessed from a Tomcat web application.  But
> >>>> I
> >>>> ran into problems using these classes in a custom Realm for Tomcat.  These
> >>>> are the errors I'm getting when the class loader initializes everything on
> >>>> Tomcat startup:
> >>>>
> >>>> Caused by: java.lang.RuntimeException: Could not initialize
> >>>> BrokerDaoConfig.
> >>>> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
> >>>> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was an
> >>>> error while building the SqlMap instance.
> >>>> --- The error occurred in the SQL Map Configuration file.
> >>>> --- The error occurred while configuring the data source.
> >>>> --- Check the data source type or class.
> >>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> >>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> >>>> java.lang.ClassCastException
> >>>>
> >>>> Can anyone shed some light on the ClassCastException?  I Googled but found
> >>>> no references to this exception in this context.
> >>>>
> >>>> As I mentioned, my classes work when all iBatis (and related) jars are
> >>>> under
> >>>> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to
> >>>> use
> >>>> the classes in a custom Realm implementation, I've placed all the jars
> >>>> under
> >>>> server/lib directory - that is the only difference between a working and
> >>>> non-working scenario.
> >>>>
> >>>> Thanks for all your help,
> >>>>
> >>>> -Sasha Borodin
> >>>>
> >>>>
> >>
> >>
> 
>

Re: ClassCastException building SqlMap instance

Posted by Sasha Borodin <sa...@whoissasha.com>.
Darn.  Seemed like a good explanation.  I will try to figure out how to
debug the Tomcat startup from within Idea; if you've done this before,
please post.

Would a ClassCastException be thrown if the instatiation failed and a null
was returned?  If not, how could an incompatible class be returned if the
fully qualified class name is supplied to the class loader, and no errors
are thrown before the cast operation?

Thanks,

-Sasha Borodin


> From: Brandon Goodin <br...@gmail.com>
> Reply-To: <ib...@incubator.apache.org>
> Date: Thu, 31 Mar 2005 20:54:11 -0700
> To: <ib...@incubator.apache.org>
> Subject: Re: ClassCastException building SqlMap instance
> 
> This is highly unlikely considering the getName() returns the
> fully-qualified class name and the package and class is imported into
> the class that is referencing. I recommend that you attach the ibatis
> source to the jar and startup tomcat in your IDE's debug mode. Set a
> breakpoint on line 303 of the SqlMapConfigParser class. You IDE will
> break on that point and you can examine what class is being passed
> back.
> 
>> From class.getName() javadoc:
> Returns the fully-qualified name of the entity (class, interface,
> array class, primitive type, or void) represented by this Class
> object, as a String.
> 
> If you don't know how to do this with your IDE i'll try to get some
> time to reproduce this in my own environment.
> 
> Brandon
> 
> On Mar 31, 2005 8:11 PM, Sasha Borodin <sa...@whoissasha.com> wrote:
>> Looking at XmlSqlMapClientBuilder.java parseDataSource() method resolves the
>> alias of "DBCP" to DbcpDataSourceFactory.class.getName(), then uses the
>> Resources class to instantiate based on the String name.
>> 
>> I think the problem is that Tomcat 5 has a class of an identical name
>> (org.apache.naming.factory.DbcpDataSourceFactory), and THIS class is
>> instantiated by the class loader instead of the iBatis one.  Hence the
>> ClassCastException when parseDataSource() tries to cast apache's
>> DbcpDataSourceFactory to DataSourceFactory (which it does NOT implement).
>> This is not a problem in a web application, as the class loader behaves
>> differently there, looking in the local resources before traversing up to
>> the parents - which is why I don't have this problem when using iBatis in
>> that scenario.
>> 
>> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/class-loader-howto.html
>> 
>> Is this a reasonable hypothesis?  If this is correct, what options do I
>> have?  I'll gladly remove one of Tomcat's jar files, if I can find which one
>> contains the offending class of the identical name.
>> 
>> Are there any options on me tweaking iBatis to correct this situation?
>> 
>> Thank you,
>> 
>> -Sasha Borodin
>> 
>>> From: Brandon Goodin <br...@gmail.com>
>>> Reply-To: <ib...@incubator.apache.org>
>>> Date: Thu, 31 Mar 2005 19:26:57 -0700
>>> To: <ib...@incubator.apache.org>
>>> Subject: Re: ClassCastException building SqlMap instance
>>> 
>>> Also, if you want to debug this error you'd be looking at
>>> SqlMpaConfigParser around line 303.
>>> 
>>> Brandon
>>> 
>>> 
>>> On Thu, 31 Mar 2005 20:21:09 -0600, Sasha Borodin <sa...@whoissasha.com>
>>> wrote:
>>>> Yes, I have ibatis-common-2.jar on the classpath.
>>>> 
>>>> I've tested my classes from within IntelliJ Idea, and implemented them
>>>> successfully in a number of web applications.  I'm not sure how to go about
>>>> debugging this particular environment, however.
>>>> 
>>>> The jars are all located in $CATALINA_HOME/server/lib, instead of the
>>>> WEB-INF/lib directory; that is the only difference that I can see - which
>>>> makes me think it's some kind of a conflict with existing jars, or there's
>>>> a
>>>> necessary jar that hasn't yet been loaded by the classloader before the
>>>> ibatis classes are initialized in this scenario.
>>>> 
>>>> If anyone has used iBatis in this context (tomcat realm implementations)
>>>> and
>>>> is familiar with any nuances, please let me know.  Also, if you have a
>>>> suggestion for debugging WHAT particular statements or code cause the
>>>> ClassCastException, that would also be very helpful to troubleshooting
>>>> this.
>>>> 
>>>>>>>> --- Check the data source type or class.
>>>>>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
>>>>>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
>>>>>>>> java.lang.ClassCastException
>>>> 
>>>> Thanks again.
>>>> 
>>>> -Sasha Borodin
>>>> 
>>>> 
>>>>> From: Brandon Goodin <br...@gmail.com>
>>>>> Reply-To: <ib...@incubator.apache.org>
>>>>> Date: Thu, 31 Mar 2005 19:04:39 -0700
>>>>> To: <ib...@incubator.apache.org>
>>>>> Subject: Re: ClassCastException building SqlMap instance
>>>>> 
>>>>> do you have the ibatis-common.jar on your classpath?
>>>>> 
>>>>> If i were you i would put this in a debugger.
>>>>> 
>>>>> Brandon
>>>>> 
>>>>> On Thu, 31 Mar 2005 19:16:50 -0600, Sasha Borodin <sa...@whoissasha.com>
>>>>> wrote:
>>>>>> Excerpt from sql-map-config.xml:
>>>>>> 
>>>>>>     <dataSource type="DBCP">
>>>>>>         <property name="JDBC.Driver"
>>>>>>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
>>>>>> 
>>>>>> The error persists whether or not I place the commons-dbcp, commons-pool,
>>>>>> commons-collections, and the jdbc driver jars in server/lib.
>>>>>> 
>>>>>> Thanks for looking at this.
>>>>>> 
>>>>>> -Sasha
>>>>>> 
>>>>>>> From: Brandon Goodin <br...@gmail.com>
>>>>>>> Reply-To: <ib...@incubator.apache.org>
>>>>>>> Date: Thu, 31 Mar 2005 18:09:02 -0700
>>>>>>> To: <ib...@incubator.apache.org>
>>>>>>> Subject: Re: ClassCastException building SqlMap instance
>>>>>>> 
>>>>>>> What are you using for your datasource?
>>>>>>> 
>>>>>>> Brandon
>>>>>>> 
>>>>>>> 
>>>>>>> On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
>>>>>>> wrote:
>>>>>>>> I've written some classes that employ the iBatis framework for data
>>>>>>>> access.
>>>>>>>> All patterns used are identical to the iBatis JPetStore example
>>>>>>>> (DaoManager,
>>>>>>>> SqlMaps, a "service" class which abstracts all this, etc.)
>>>>>>>> 
>>>>>>>> These classes work great when accessed from a Tomcat web application.
>>>>>>>> But
>>>>>>>> I
>>>>>>>> ran into problems using these classes in a custom Realm for Tomcat.
>>>>>>>> These
>>>>>>>> are the errors I'm getting when the class loader initializes everything
>>>>>>>> on
>>>>>>>> Tomcat startup:
>>>>>>>> 
>>>>>>>> Caused by: java.lang.RuntimeException: Could not initialize
>>>>>>>> BrokerDaoConfig.
>>>>>>>> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
>>>>>>>> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was
>>>>>>>> an
>>>>>>>> error while building the SqlMap instance.
>>>>>>>> --- The error occurred in the SQL Map Configuration file.
>>>>>>>> --- The error occurred while configuring the data source.
>>>>>>>> --- Check the data source type or class.
>>>>>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
>>>>>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
>>>>>>>> java.lang.ClassCastException
>>>>>>>> 
>>>>>>>> Can anyone shed some light on the ClassCastException?  I Googled but
>>>>>>>> found
>>>>>>>> no references to this exception in this context.
>>>>>>>> 
>>>>>>>> As I mentioned, my classes work when all iBatis (and related) jars are
>>>>>>>> under
>>>>>>>> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying
>>>>>>>> to
>>>>>>>> use
>>>>>>>> the classes in a custom Realm implementation, I've placed all the jars
>>>>>>>> under
>>>>>>>> server/lib directory - that is the only difference between a working
>>>>>>>> and
>>>>>>>> non-working scenario.
>>>>>>>> 
>>>>>>>> Thanks for all your help,
>>>>>>>> 
>>>>>>>> -Sasha Borodin
>>>>>>>> 
>>>>>>>> 
>>>>>> 
>>>>>> 
>>>> 
>>>> 
>> 
>> 



Re: ClassCastException building SqlMap instance

Posted by Brandon Goodin <br...@gmail.com>.
This is highly unlikely considering the getName() returns the
fully-qualified class name and the package and class is imported into
the class that is referencing. I recommend that you attach the ibatis
source to the jar and startup tomcat in your IDE's debug mode. Set a
breakpoint on line 303 of the SqlMapConfigParser class. You IDE will
break on that point and you can examine what class is being passed
back.

>From class.getName() javadoc:
Returns the fully-qualified name of the entity (class, interface,
array class, primitive type, or void) represented by this Class
object, as a String.

If you don't know how to do this with your IDE i'll try to get some
time to reproduce this in my own environment.

Brandon

On Mar 31, 2005 8:11 PM, Sasha Borodin <sa...@whoissasha.com> wrote:
> Looking at XmlSqlMapClientBuilder.java parseDataSource() method resolves the
> alias of "DBCP" to DbcpDataSourceFactory.class.getName(), then uses the
> Resources class to instantiate based on the String name.
> 
> I think the problem is that Tomcat 5 has a class of an identical name
> (org.apache.naming.factory.DbcpDataSourceFactory), and THIS class is
> instantiated by the class loader instead of the iBatis one.  Hence the
> ClassCastException when parseDataSource() tries to cast apache's
> DbcpDataSourceFactory to DataSourceFactory (which it does NOT implement).
> This is not a problem in a web application, as the class loader behaves
> differently there, looking in the local resources before traversing up to
> the parents - which is why I don't have this problem when using iBatis in
> that scenario.
> 
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/class-loader-howto.html
> 
> Is this a reasonable hypothesis?  If this is correct, what options do I
> have?  I'll gladly remove one of Tomcat's jar files, if I can find which one
> contains the offending class of the identical name.
> 
> Are there any options on me tweaking iBatis to correct this situation?
> 
> Thank you,
> 
> -Sasha Borodin
> 
> > From: Brandon Goodin <br...@gmail.com>
> > Reply-To: <ib...@incubator.apache.org>
> > Date: Thu, 31 Mar 2005 19:26:57 -0700
> > To: <ib...@incubator.apache.org>
> > Subject: Re: ClassCastException building SqlMap instance
> >
> > Also, if you want to debug this error you'd be looking at
> > SqlMpaConfigParser around line 303.
> >
> > Brandon
> >
> >
> > On Thu, 31 Mar 2005 20:21:09 -0600, Sasha Borodin <sa...@whoissasha.com>
> > wrote:
> >> Yes, I have ibatis-common-2.jar on the classpath.
> >>
> >> I've tested my classes from within IntelliJ Idea, and implemented them
> >> successfully in a number of web applications.  I'm not sure how to go about
> >> debugging this particular environment, however.
> >>
> >> The jars are all located in $CATALINA_HOME/server/lib, instead of the
> >> WEB-INF/lib directory; that is the only difference that I can see - which
> >> makes me think it's some kind of a conflict with existing jars, or there's a
> >> necessary jar that hasn't yet been loaded by the classloader before the
> >> ibatis classes are initialized in this scenario.
> >>
> >> If anyone has used iBatis in this context (tomcat realm implementations) and
> >> is familiar with any nuances, please let me know.  Also, if you have a
> >> suggestion for debugging WHAT particular statements or code cause the
> >> ClassCastException, that would also be very helpful to troubleshooting this.
> >>
> >>>>>> --- Check the data source type or class.
> >>>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> >>>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> >>>>>> java.lang.ClassCastException
> >>
> >> Thanks again.
> >>
> >> -Sasha Borodin
> >>
> >>
> >>> From: Brandon Goodin <br...@gmail.com>
> >>> Reply-To: <ib...@incubator.apache.org>
> >>> Date: Thu, 31 Mar 2005 19:04:39 -0700
> >>> To: <ib...@incubator.apache.org>
> >>> Subject: Re: ClassCastException building SqlMap instance
> >>>
> >>> do you have the ibatis-common.jar on your classpath?
> >>>
> >>> If i were you i would put this in a debugger.
> >>>
> >>> Brandon
> >>>
> >>> On Thu, 31 Mar 2005 19:16:50 -0600, Sasha Borodin <sa...@whoissasha.com>
> >>> wrote:
> >>>> Excerpt from sql-map-config.xml:
> >>>>
> >>>>     <dataSource type="DBCP">
> >>>>         <property name="JDBC.Driver"
> >>>>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
> >>>>
> >>>> The error persists whether or not I place the commons-dbcp, commons-pool,
> >>>> commons-collections, and the jdbc driver jars in server/lib.
> >>>>
> >>>> Thanks for looking at this.
> >>>>
> >>>> -Sasha
> >>>>
> >>>>> From: Brandon Goodin <br...@gmail.com>
> >>>>> Reply-To: <ib...@incubator.apache.org>
> >>>>> Date: Thu, 31 Mar 2005 18:09:02 -0700
> >>>>> To: <ib...@incubator.apache.org>
> >>>>> Subject: Re: ClassCastException building SqlMap instance
> >>>>>
> >>>>> What are you using for your datasource?
> >>>>>
> >>>>> Brandon
> >>>>>
> >>>>>
> >>>>> On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
> >>>>> wrote:
> >>>>>> I've written some classes that employ the iBatis framework for data
> >>>>>> access.
> >>>>>> All patterns used are identical to the iBatis JPetStore example
> >>>>>> (DaoManager,
> >>>>>> SqlMaps, a "service" class which abstracts all this, etc.)
> >>>>>>
> >>>>>> These classes work great when accessed from a Tomcat web application.
> >>>>>> But
> >>>>>> I
> >>>>>> ran into problems using these classes in a custom Realm for Tomcat.
> >>>>>> These
> >>>>>> are the errors I'm getting when the class loader initializes everything
> >>>>>> on
> >>>>>> Tomcat startup:
> >>>>>>
> >>>>>> Caused by: java.lang.RuntimeException: Could not initialize
> >>>>>> BrokerDaoConfig.
> >>>>>> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
> >>>>>> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was
> >>>>>> an
> >>>>>> error while building the SqlMap instance.
> >>>>>> --- The error occurred in the SQL Map Configuration file.
> >>>>>> --- The error occurred while configuring the data source.
> >>>>>> --- Check the data source type or class.
> >>>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> >>>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> >>>>>> java.lang.ClassCastException
> >>>>>>
> >>>>>> Can anyone shed some light on the ClassCastException?  I Googled but
> >>>>>> found
> >>>>>> no references to this exception in this context.
> >>>>>>
> >>>>>> As I mentioned, my classes work when all iBatis (and related) jars are
> >>>>>> under
> >>>>>> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to
> >>>>>> use
> >>>>>> the classes in a custom Realm implementation, I've placed all the jars
> >>>>>> under
> >>>>>> server/lib directory - that is the only difference between a working and
> >>>>>> non-working scenario.
> >>>>>>
> >>>>>> Thanks for all your help,
> >>>>>>
> >>>>>> -Sasha Borodin
> >>>>>>
> >>>>>>
> >>>>
> >>>>
> >>
> >>
> 
>

Re: ClassCastException building SqlMap instance

Posted by Sasha Borodin <sa...@whoissasha.com>.
Looking at XmlSqlMapClientBuilder.java parseDataSource() method resolves the
alias of "DBCP" to DbcpDataSourceFactory.class.getName(), then uses the
Resources class to instantiate based on the String name.

I think the problem is that Tomcat 5 has a class of an identical name
(org.apache.naming.factory.DbcpDataSourceFactory), and THIS class is
instantiated by the class loader instead of the iBatis one.  Hence the
ClassCastException when parseDataSource() tries to cast apache's
DbcpDataSourceFactory to DataSourceFactory (which it does NOT implement).
This is not a problem in a web application, as the class loader behaves
differently there, looking in the local resources before traversing up to
the parents - which is why I don't have this problem when using iBatis in
that scenario.

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/class-loader-howto.html

Is this a reasonable hypothesis?  If this is correct, what options do I
have?  I'll gladly remove one of Tomcat's jar files, if I can find which one
contains the offending class of the identical name.

Are there any options on me tweaking iBatis to correct this situation?

Thank you,

-Sasha Borodin


> From: Brandon Goodin <br...@gmail.com>
> Reply-To: <ib...@incubator.apache.org>
> Date: Thu, 31 Mar 2005 19:26:57 -0700
> To: <ib...@incubator.apache.org>
> Subject: Re: ClassCastException building SqlMap instance
> 
> Also, if you want to debug this error you'd be looking at
> SqlMpaConfigParser around line 303.
> 
> Brandon
> 
> 
> On Thu, 31 Mar 2005 20:21:09 -0600, Sasha Borodin <sa...@whoissasha.com>
> wrote:
>> Yes, I have ibatis-common-2.jar on the classpath.
>> 
>> I've tested my classes from within IntelliJ Idea, and implemented them
>> successfully in a number of web applications.  I'm not sure how to go about
>> debugging this particular environment, however.
>> 
>> The jars are all located in $CATALINA_HOME/server/lib, instead of the
>> WEB-INF/lib directory; that is the only difference that I can see - which
>> makes me think it's some kind of a conflict with existing jars, or there's a
>> necessary jar that hasn't yet been loaded by the classloader before the
>> ibatis classes are initialized in this scenario.
>> 
>> If anyone has used iBatis in this context (tomcat realm implementations) and
>> is familiar with any nuances, please let me know.  Also, if you have a
>> suggestion for debugging WHAT particular statements or code cause the
>> ClassCastException, that would also be very helpful to troubleshooting this.
>> 
>>>>>> --- Check the data source type or class.
>>>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
>>>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
>>>>>> java.lang.ClassCastException
>> 
>> Thanks again.
>> 
>> -Sasha Borodin
>> 
>> 
>>> From: Brandon Goodin <br...@gmail.com>
>>> Reply-To: <ib...@incubator.apache.org>
>>> Date: Thu, 31 Mar 2005 19:04:39 -0700
>>> To: <ib...@incubator.apache.org>
>>> Subject: Re: ClassCastException building SqlMap instance
>>> 
>>> do you have the ibatis-common.jar on your classpath?
>>> 
>>> If i were you i would put this in a debugger.
>>> 
>>> Brandon
>>> 
>>> On Thu, 31 Mar 2005 19:16:50 -0600, Sasha Borodin <sa...@whoissasha.com>
>>> wrote:
>>>> Excerpt from sql-map-config.xml:
>>>> 
>>>>     <dataSource type="DBCP">
>>>>         <property name="JDBC.Driver"
>>>>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
>>>> 
>>>> The error persists whether or not I place the commons-dbcp, commons-pool,
>>>> commons-collections, and the jdbc driver jars in server/lib.
>>>> 
>>>> Thanks for looking at this.
>>>> 
>>>> -Sasha
>>>> 
>>>>> From: Brandon Goodin <br...@gmail.com>
>>>>> Reply-To: <ib...@incubator.apache.org>
>>>>> Date: Thu, 31 Mar 2005 18:09:02 -0700
>>>>> To: <ib...@incubator.apache.org>
>>>>> Subject: Re: ClassCastException building SqlMap instance
>>>>> 
>>>>> What are you using for your datasource?
>>>>> 
>>>>> Brandon
>>>>> 
>>>>> 
>>>>> On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
>>>>> wrote:
>>>>>> I've written some classes that employ the iBatis framework for data
>>>>>> access.
>>>>>> All patterns used are identical to the iBatis JPetStore example
>>>>>> (DaoManager,
>>>>>> SqlMaps, a "service" class which abstracts all this, etc.)
>>>>>> 
>>>>>> These classes work great when accessed from a Tomcat web application.
>>>>>> But
>>>>>> I
>>>>>> ran into problems using these classes in a custom Realm for Tomcat.
>>>>>> These
>>>>>> are the errors I'm getting when the class loader initializes everything
>>>>>> on
>>>>>> Tomcat startup:
>>>>>> 
>>>>>> Caused by: java.lang.RuntimeException: Could not initialize
>>>>>> BrokerDaoConfig.
>>>>>> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
>>>>>> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was
>>>>>> an
>>>>>> error while building the SqlMap instance.
>>>>>> --- The error occurred in the SQL Map Configuration file.
>>>>>> --- The error occurred while configuring the data source.
>>>>>> --- Check the data source type or class.
>>>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
>>>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
>>>>>> java.lang.ClassCastException
>>>>>> 
>>>>>> Can anyone shed some light on the ClassCastException?  I Googled but
>>>>>> found
>>>>>> no references to this exception in this context.
>>>>>> 
>>>>>> As I mentioned, my classes work when all iBatis (and related) jars are
>>>>>> under
>>>>>> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to
>>>>>> use
>>>>>> the classes in a custom Realm implementation, I've placed all the jars
>>>>>> under
>>>>>> server/lib directory - that is the only difference between a working and
>>>>>> non-working scenario.
>>>>>> 
>>>>>> Thanks for all your help,
>>>>>> 
>>>>>> -Sasha Borodin
>>>>>> 
>>>>>> 
>>>> 
>>>> 
>> 
>> 



Re: ClassCastException building SqlMap instance

Posted by Brandon Goodin <br...@gmail.com>.
Also, if you want to debug this error you'd be looking at
SqlMpaConfigParser around line 303.

Brandon


On Thu, 31 Mar 2005 20:21:09 -0600, Sasha Borodin <sa...@whoissasha.com> wrote:
> Yes, I have ibatis-common-2.jar on the classpath.
> 
> I've tested my classes from within IntelliJ Idea, and implemented them
> successfully in a number of web applications.  I'm not sure how to go about
> debugging this particular environment, however.
> 
> The jars are all located in $CATALINA_HOME/server/lib, instead of the
> WEB-INF/lib directory; that is the only difference that I can see - which
> makes me think it's some kind of a conflict with existing jars, or there's a
> necessary jar that hasn't yet been loaded by the classloader before the
> ibatis classes are initialized in this scenario.
> 
> If anyone has used iBatis in this context (tomcat realm implementations) and
> is familiar with any nuances, please let me know.  Also, if you have a
> suggestion for debugging WHAT particular statements or code cause the
> ClassCastException, that would also be very helpful to troubleshooting this.
> 
> >>>> --- Check the data source type or class.
> >>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> >>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> >>>> java.lang.ClassCastException
> 
> Thanks again.
> 
> -Sasha Borodin
> 
> 
> > From: Brandon Goodin <br...@gmail.com>
> > Reply-To: <ib...@incubator.apache.org>
> > Date: Thu, 31 Mar 2005 19:04:39 -0700
> > To: <ib...@incubator.apache.org>
> > Subject: Re: ClassCastException building SqlMap instance
> >
> > do you have the ibatis-common.jar on your classpath?
> >
> > If i were you i would put this in a debugger.
> >
> > Brandon
> >
> > On Thu, 31 Mar 2005 19:16:50 -0600, Sasha Borodin <sa...@whoissasha.com>
> > wrote:
> >> Excerpt from sql-map-config.xml:
> >>
> >>     <dataSource type="DBCP">
> >>         <property name="JDBC.Driver"
> >>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
> >>
> >> The error persists whether or not I place the commons-dbcp, commons-pool,
> >> commons-collections, and the jdbc driver jars in server/lib.
> >>
> >> Thanks for looking at this.
> >>
> >> -Sasha
> >>
> >>> From: Brandon Goodin <br...@gmail.com>
> >>> Reply-To: <ib...@incubator.apache.org>
> >>> Date: Thu, 31 Mar 2005 18:09:02 -0700
> >>> To: <ib...@incubator.apache.org>
> >>> Subject: Re: ClassCastException building SqlMap instance
> >>>
> >>> What are you using for your datasource?
> >>>
> >>> Brandon
> >>>
> >>>
> >>> On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
> >>> wrote:
> >>>> I've written some classes that employ the iBatis framework for data access.
> >>>> All patterns used are identical to the iBatis JPetStore example
> >>>> (DaoManager,
> >>>> SqlMaps, a "service" class which abstracts all this, etc.)
> >>>>
> >>>> These classes work great when accessed from a Tomcat web application.  But
> >>>> I
> >>>> ran into problems using these classes in a custom Realm for Tomcat.  These
> >>>> are the errors I'm getting when the class loader initializes everything on
> >>>> Tomcat startup:
> >>>>
> >>>> Caused by: java.lang.RuntimeException: Could not initialize
> >>>> BrokerDaoConfig.
> >>>> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
> >>>> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was an
> >>>> error while building the SqlMap instance.
> >>>> --- The error occurred in the SQL Map Configuration file.
> >>>> --- The error occurred while configuring the data source.
> >>>> --- Check the data source type or class.
> >>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> >>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> >>>> java.lang.ClassCastException
> >>>>
> >>>> Can anyone shed some light on the ClassCastException?  I Googled but found
> >>>> no references to this exception in this context.
> >>>>
> >>>> As I mentioned, my classes work when all iBatis (and related) jars are
> >>>> under
> >>>> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to
> >>>> use
> >>>> the classes in a custom Realm implementation, I've placed all the jars
> >>>> under
> >>>> server/lib directory - that is the only difference between a working and
> >>>> non-working scenario.
> >>>>
> >>>> Thanks for all your help,
> >>>>
> >>>> -Sasha Borodin
> >>>>
> >>>>
> >>
> >>
> 
>

Re: ClassCastException building SqlMap instance

Posted by Sasha Borodin <sa...@whoissasha.com>.
Yes, I have ibatis-common-2.jar on the classpath.

I've tested my classes from within IntelliJ Idea, and implemented them
successfully in a number of web applications.  I'm not sure how to go about
debugging this particular environment, however.

The jars are all located in $CATALINA_HOME/server/lib, instead of the
WEB-INF/lib directory; that is the only difference that I can see - which
makes me think it's some kind of a conflict with existing jars, or there's a
necessary jar that hasn't yet been loaded by the classloader before the
ibatis classes are initialized in this scenario.

If anyone has used iBatis in this context (tomcat realm implementations) and
is familiar with any nuances, please let me know.  Also, if you have a
suggestion for debugging WHAT particular statements or code cause the
ClassCastException, that would also be very helpful to troubleshooting this.

>>>> --- Check the data source type or class.
>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
>>>> java.lang.ClassCastException

Thanks again.

-Sasha Borodin


> From: Brandon Goodin <br...@gmail.com>
> Reply-To: <ib...@incubator.apache.org>
> Date: Thu, 31 Mar 2005 19:04:39 -0700
> To: <ib...@incubator.apache.org>
> Subject: Re: ClassCastException building SqlMap instance
> 
> do you have the ibatis-common.jar on your classpath?
> 
> If i were you i would put this in a debugger.
> 
> Brandon
> 
> On Thu, 31 Mar 2005 19:16:50 -0600, Sasha Borodin <sa...@whoissasha.com>
> wrote:
>> Excerpt from sql-map-config.xml:
>> 
>>     <dataSource type="DBCP">
>>         <property name="JDBC.Driver"
>>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
>> 
>> The error persists whether or not I place the commons-dbcp, commons-pool,
>> commons-collections, and the jdbc driver jars in server/lib.
>> 
>> Thanks for looking at this.
>> 
>> -Sasha
>> 
>>> From: Brandon Goodin <br...@gmail.com>
>>> Reply-To: <ib...@incubator.apache.org>
>>> Date: Thu, 31 Mar 2005 18:09:02 -0700
>>> To: <ib...@incubator.apache.org>
>>> Subject: Re: ClassCastException building SqlMap instance
>>> 
>>> What are you using for your datasource?
>>> 
>>> Brandon
>>> 
>>> 
>>> On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
>>> wrote:
>>>> I've written some classes that employ the iBatis framework for data access.
>>>> All patterns used are identical to the iBatis JPetStore example
>>>> (DaoManager,
>>>> SqlMaps, a "service" class which abstracts all this, etc.)
>>>> 
>>>> These classes work great when accessed from a Tomcat web application.  But
>>>> I
>>>> ran into problems using these classes in a custom Realm for Tomcat.  These
>>>> are the errors I'm getting when the class loader initializes everything on
>>>> Tomcat startup:
>>>> 
>>>> Caused by: java.lang.RuntimeException: Could not initialize
>>>> BrokerDaoConfig.
>>>> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
>>>> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was an
>>>> error while building the SqlMap instance.
>>>> --- The error occurred in the SQL Map Configuration file.
>>>> --- The error occurred while configuring the data source.
>>>> --- Check the data source type or class.
>>>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
>>>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
>>>> java.lang.ClassCastException
>>>> 
>>>> Can anyone shed some light on the ClassCastException?  I Googled but found
>>>> no references to this exception in this context.
>>>> 
>>>> As I mentioned, my classes work when all iBatis (and related) jars are
>>>> under
>>>> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to
>>>> use
>>>> the classes in a custom Realm implementation, I've placed all the jars
>>>> under
>>>> server/lib directory - that is the only difference between a working and
>>>> non-working scenario.
>>>> 
>>>> Thanks for all your help,
>>>> 
>>>> -Sasha Borodin
>>>> 
>>>> 
>> 
>> 



Re: ClassCastException building SqlMap instance

Posted by Brandon Goodin <br...@gmail.com>.
do you have the ibatis-common.jar on your classpath?

If i were you i would put this in a debugger.

Brandon

On Thu, 31 Mar 2005 19:16:50 -0600, Sasha Borodin <sa...@whoissasha.com> wrote:
> Excerpt from sql-map-config.xml:
> 
>     <dataSource type="DBCP">
>         <property name="JDBC.Driver"
>             value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
> 
> The error persists whether or not I place the commons-dbcp, commons-pool,
> commons-collections, and the jdbc driver jars in server/lib.
> 
> Thanks for looking at this.
> 
> -Sasha
> 
> > From: Brandon Goodin <br...@gmail.com>
> > Reply-To: <ib...@incubator.apache.org>
> > Date: Thu, 31 Mar 2005 18:09:02 -0700
> > To: <ib...@incubator.apache.org>
> > Subject: Re: ClassCastException building SqlMap instance
> >
> > What are you using for your datasource?
> >
> > Brandon
> >
> >
> > On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
> > wrote:
> >> I've written some classes that employ the iBatis framework for data access.
> >> All patterns used are identical to the iBatis JPetStore example (DaoManager,
> >> SqlMaps, a "service" class which abstracts all this, etc.)
> >>
> >> These classes work great when accessed from a Tomcat web application.  But I
> >> ran into problems using these classes in a custom Realm for Tomcat.  These
> >> are the errors I'm getting when the class loader initializes everything on
> >> Tomcat startup:
> >>
> >> Caused by: java.lang.RuntimeException: Could not initialize BrokerDaoConfig.
> >> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
> >> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was an
> >> error while building the SqlMap instance.
> >> --- The error occurred in the SQL Map Configuration file.
> >> --- The error occurred while configuring the data source.
> >> --- Check the data source type or class.
> >> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
> >> DataSource.  Could not instantiate DataSourceFactory.  Cause:
> >> java.lang.ClassCastException
> >>
> >> Can anyone shed some light on the ClassCastException?  I Googled but found
> >> no references to this exception in this context.
> >>
> >> As I mentioned, my classes work when all iBatis (and related) jars are under
> >> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to use
> >> the classes in a custom Realm implementation, I've placed all the jars under
> >> server/lib directory - that is the only difference between a working and
> >> non-working scenario.
> >>
> >> Thanks for all your help,
> >>
> >> -Sasha Borodin
> >>
> >>
> 
>

Re: ClassCastException building SqlMap instance

Posted by Sasha Borodin <sa...@whoissasha.com>.
Excerpt from sql-map-config.xml:

    <dataSource type="DBCP">
        <property name="JDBC.Driver"
            value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>


The error persists whether or not I place the commons-dbcp, commons-pool,
commons-collections, and the jdbc driver jars in server/lib.
 
Thanks for looking at this.

-Sasha

> From: Brandon Goodin <br...@gmail.com>
> Reply-To: <ib...@incubator.apache.org>
> Date: Thu, 31 Mar 2005 18:09:02 -0700
> To: <ib...@incubator.apache.org>
> Subject: Re: ClassCastException building SqlMap instance
> 
> What are you using for your datasource?
> 
> Brandon
> 
> 
> On Thu, 31 Mar 2005 18:32:57 -0600, Sasha Borodin <sa...@whoissasha.com>
> wrote:
>> I've written some classes that employ the iBatis framework for data access.
>> All patterns used are identical to the iBatis JPetStore example (DaoManager,
>> SqlMaps, a "service" class which abstracts all this, etc.)
>> 
>> These classes work great when accessed from a Tomcat web application.  But I
>> ran into problems using these classes in a custom Realm for Tomcat.  These
>> are the errors I'm getting when the class loader initializes everything on
>> Tomcat startup:
>> 
>> Caused by: java.lang.RuntimeException: Could not initialize BrokerDaoConfig.
>> Cause:  com.ibatis.dao.client.DaoException: Error while configuring
>> DaoManager.  Cause: com.ibatis.sqlmap.client.SqlMapException: There was an
>> error while building the SqlMap instance.
>> --- The error occurred in the SQL Map Configuration file.
>> --- The error occurred while configuring the data source.
>> --- Check the data source type or class.
>> --- Cause: com.ibatis.sqlmap.client.SqlMapException: Error initializing
>> DataSource.  Could not instantiate DataSourceFactory.  Cause:
>> java.lang.ClassCastException
>> 
>> Can anyone shed some light on the ClassCastException?  I Googled but found
>> no references to this exception in this context.
>> 
>> As I mentioned, my classes work when all iBatis (and related) jars are under
>> a webapp's WEB-INF/lib directory.  But in this case, since I'm trying to use
>> the classes in a custom Realm implementation, I've placed all the jars under
>> server/lib directory - that is the only difference between a working and
>> non-working scenario.
>> 
>> Thanks for all your help,
>> 
>> -Sasha Borodin
>> 
>>