You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tim Christopher <ti...@gmail.com> on 2005/02/21 05:28:08 UTC

Struts and iBATIS

Hi,

I'm in the middle of incorporating iBATIS into my Struts project, but
am having slight trouble in getting it to work.

The problem starts when I call sqlMap.startTransaction() from within
my BaseDAO file as I get a null pointer exception...  Yet when I print
out the value of sqlMap I get something like
"com.ibatis.sqlmap.engine.impl.SqlMapClientImpl@1d8c528" - not null as
I would have expected given the null pointer error.  Sadly I do not
know of any methods I can call that show the state of the sqlMap.

Having made various small alterations to the code to try and get it to
work I eventually tried removing the line to start the transaction... 
However this resulted in the following error:

com.ibatis.sqlmap.client.SqlMapException: There is no statement named
insertModule in this SqlMap.
    ...SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:288)
    ...SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:491)
    ...SqlMapSessionImpl.update(SqlMapSessionImpl.java:89)
    ...SqlMapClientImpl.update(SqlMapClientImpl.java:61)
    ...com.xyz.BaseDAO.update(BaseDAO.java:101)
    <snip/>

This leaves me at a point where I'm not certain if this means there is
a problem with my XML config file (ie. it's looking, but can't find
the statement), or if it looking in an empty object - though I'm
guessing (hoping) that fixing the first null pointer error should make
it all work fine.

Any help / suggestions apreciated.

Tim Christopher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and iBATIS

Posted by Richard Yee <ry...@cruzio.com>.
Tim,
I think that depends on which application server you are using. In my case, 
I'm using Oracle's OC4J. It uses a file called datasources.xml to define 
datasources. In Resin, the datasource is defined in the web.xml file using 
the <database> element.
What app server are you using?

-Richard

I have the datasource defined At 02:08 PM 2/21/2005, you wrote:
>Cheers for the advice.
>
>I've decided I'm going to start again with iBATIS and try to follow
>the jPetStore example to get it to work (instead of the one at
>http://www.reumann.net/struts/ibatisLesson1/step1.do)...  I just have
>a quick question about your reply though:
>
> >> <property name="DataSource" value="jdbc/myDatasourceName"/>
>
>Where abouts should the datasource be defined?  I've currently got a
>datasource defined in the server.xml file called "sisDatasource",
>though the pet store example doesn't include a server.xml file so I'm
>assuming they must rely on value="${drive}" etc to pull the details
>from a database.properties file.
>
>I'm all ok with that, but I don't see where a name for this datasource
>is defined.  Going back to the pet store example it refers to the
>datasource in the web.xml file as jdbc/jpetstore1 but I can't find any
>element with that name in the configuration files.
>
>Tim Christopher
>
>On Mon, 21 Feb 2005 08:23:55 -0800, Richard Yee <ry...@cruzio.com> wrote:
> > Tim,
> > Without seeing the entire sqlMapConfig.xml it's going to be hard for anyone
> > to figure out exactly what the problem is. You can get more direct help by
> > posting at ibatis-user-java@incubator.apache.org.
> >
> > I think you also need a DataSource property in your transactionManager.
> > This is what I use. I don't set DBInitialContext or DBLookup.
> >   <transactionManager type="JDBC" >
> >     <dataSource type="JNDI">
> >       <property name="DataSource" value="jdbc/myDatasourceName"/>
> >     </dataSource>
> > </transactionManager>
> >
> > Are you using the iBATIS DaoManager?
> > Regards,
> >
> > Richard
> > <snip>
> > At 07:01 AM 2/21/2005, you wrote:
> > >Here's an extract from my sql config file:
> > >
> > >###################
> > ><insert id="insertModule" parameterClass="com.test.dto.Module">
> > >   INSERT INTO tbl_Module ( module_id, module_credits, module_semester,
> > >module_level, module_description )
> > >   VALUES ( #id#, #credits#, #semester#, #year#, #description# )
> > ></insert>
> > >###################
> > </snip>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and iBATIS

Posted by Richard Yee <ry...@cruzio.com>.
Tim,
If you are using Tomcat, you would set up a resource in the server.xml

<Resource name="jdbc/TestDB"
                auth="Container"
                type="javax.sql.DataSource"/>
.
.
.

and in your web.xml you would have a resource-ref tag like this:

   <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/TestDB</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>


-Richard
At 02:08 PM 2/21/2005, you wrote:
>Cheers for the advice.
>
>I've decided I'm going to start again with iBATIS and try to follow
>the jPetStore example to get it to work (instead of the one at
>http://www.reumann.net/struts/ibatisLesson1/step1.do)...  I just have
>a quick question about your reply though:
>
> >> <property name="DataSource" value="jdbc/myDatasourceName"/>
>
>Where abouts should the datasource be defined?  I've currently got a
>datasource defined in the server.xml file called "sisDatasource",
>though the pet store example doesn't include a server.xml file so I'm
>assuming they must rely on value="${drive}" etc to pull the details
>from a database.properties file.
>
>I'm all ok with that, but I don't see where a name for this datasource
>is defined.  Going back to the pet store example it refers to the
>datasource in the web.xml file as jdbc/jpetstore1 but I can't find any
>element with that name in the configuration files.
>
>Tim Christopher
>
>On Mon, 21 Feb 2005 08:23:55 -0800, Richard Yee <ry...@cruzio.com> wrote:
> > Tim,
> > Without seeing the entire sqlMapConfig.xml it's going to be hard for anyone
> > to figure out exactly what the problem is. You can get more direct help by
> > posting at ibatis-user-java@incubator.apache.org.
> >
> > I think you also need a DataSource property in your transactionManager.
> > This is what I use. I don't set DBInitialContext or DBLookup.
> >   <transactionManager type="JDBC" >
> >     <dataSource type="JNDI">
> >       <property name="DataSource" value="jdbc/myDatasourceName"/>
> >     </dataSource>
> > </transactionManager>
> >
> > Are you using the iBATIS DaoManager?
> > Regards,
> >
> > Richard
> > <snip>
> > At 07:01 AM 2/21/2005, you wrote:
> > >Here's an extract from my sql config file:
> > >
> > >###################
> > ><insert id="insertModule" parameterClass="com.test.dto.Module">
> > >   INSERT INTO tbl_Module ( module_id, module_credits, module_semester,
> > >module_level, module_description )
> > >   VALUES ( #id#, #credits#, #semester#, #year#, #description# )
> > ></insert>
> > >###################
> > </snip>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org

Re: Struts and iBATIS

Posted by Tim Christopher <ti...@gmail.com>.
Cheers for the advice.

I've decided I'm going to start again with iBATIS and try to follow
the jPetStore example to get it to work (instead of the one at
http://www.reumann.net/struts/ibatisLesson1/step1.do)...  I just have
a quick question about your reply though:

>> <property name="DataSource" value="jdbc/myDatasourceName"/>

Where abouts should the datasource be defined?  I've currently got a
datasource defined in the server.xml file called "sisDatasource",
though the pet store example doesn't include a server.xml file so I'm
assuming they must rely on value="${drive}" etc to pull the details
from a database.properties file.

I'm all ok with that, but I don't see where a name for this datasource
is defined.  Going back to the pet store example it refers to the
datasource in the web.xml file as jdbc/jpetstore1 but I can't find any
element with that name in the configuration files.

Tim Christopher

On Mon, 21 Feb 2005 08:23:55 -0800, Richard Yee <ry...@cruzio.com> wrote:
> Tim,
> Without seeing the entire sqlMapConfig.xml it's going to be hard for anyone
> to figure out exactly what the problem is. You can get more direct help by
> posting at ibatis-user-java@incubator.apache.org.
> 
> I think you also need a DataSource property in your transactionManager.
> This is what I use. I don't set DBInitialContext or DBLookup.
>   <transactionManager type="JDBC" >
>     <dataSource type="JNDI">
>       <property name="DataSource" value="jdbc/myDatasourceName"/>
>     </dataSource>
> </transactionManager>
> 
> Are you using the iBATIS DaoManager?
> Regards,
> 
> Richard
> <snip>
> At 07:01 AM 2/21/2005, you wrote:
> >Here's an extract from my sql config file:
> >
> >###################
> ><insert id="insertModule" parameterClass="com.test.dto.Module">
> >   INSERT INTO tbl_Module ( module_id, module_credits, module_semester,
> >module_level, module_description )
> >   VALUES ( #id#, #credits#, #semester#, #year#, #description# )
> ></insert>
> >###################
> </snip>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and iBATIS

Posted by Richard Yee <ry...@cruzio.com>.
Tim,
Without seeing the entire sqlMapConfig.xml it's going to be hard for anyone 
to figure out exactly what the problem is. You can get more direct help by 
posting at ibatis-user-java@incubator.apache.org.

I think you also need a DataSource property in your transactionManager. 
This is what I use. I don't set DBInitialContext or DBLookup.
   <transactionManager type="JDBC" >
     <dataSource type="JNDI">
       <property name="DataSource" value="jdbc/myDatasourceName"/>
     </dataSource>
</transactionManager>

Are you using the iBATIS DaoManager?
Regards,

Richard
<snip>
At 07:01 AM 2/21/2005, you wrote:
>Here's an extract from my sql config file:
>
>###################
><insert id="insertModule" parameterClass="com.test.dto.Module">
>   INSERT INTO tbl_Module ( module_id, module_credits, module_semester,
>module_level, module_description )
>   VALUES ( #id#, #credits#, #semester#, #year#, #description# )
></insert>
>###################
</snip> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and iBATIS

Posted by Tim Christopher <ti...@gmail.com>.
Here's an extract from my sql config file:

###################
<insert id="insertModule" parameterClass="com.test.dto.Module">
  INSERT INTO tbl_Module ( module_id, module_credits, module_semester,
module_level, module_description )
  VALUES ( #id#, #credits#, #semester#, #year#, #description# )
</insert>
###################

I've tried a few variations of this, for example using statement tag
instead of the insert tag.

On a positive note I think I've worked out why the transactions bit
was failing - I was using old SQL Map Config 1.0 dtd that doesn't have
a transaction tag (that I know of), instead of the new 2,0 (which
does)...  Unfortunately when I run my code I get a NoClassDefFound
error with regards to my BaseDAO, although when I put a print
statement in the static bit at the top that loads in the sql config
file it is still printed - so surely the file is there?

Below is an extract from both the old and new config files.  In the
old one the datasource refers to <ResourceParams> in the server.xml
file.  Can anyone suggest how  can make the second one equilivent, or
make it so I can remove the information from the server.xml file to
somewhere within my project.

## Old ##
<datasource name="sisDatasource"
factory-class="....JndiDataSourceFactory" default="true" >
  <property name="DBInitialContext" value= "java:comp/env" />
  <property name="DBLookup"         value="${DatabaseJNDIPath}"/>
</datasource>

## New ##
<transactionManager type="JDBC">
  <dataSource type="JNDI">
    <property name="DBInitialContext" value= "java:comp/env" />
    <property name="DBLookup"         value="${DatabaseJNDIPath}"/>
  </dataSource>
</transactionManager>

Tim Christopher

On Sun, 20 Feb 2005 21:37:57 -0700, Larry Meadors
<la...@gmail.com> wrote:
> The code there is:
> 
> ===
>    MappedStatement ms = (MappedStatement) mappedStatements.get(id);
>    if (ms == null) {
>      throw new SqlMapException("There is no statement named " + id +
> " in this SqlMap.");
>    }
>    return ms;
> ===
> 
> Looks like you have a sqlmap, but that the statement "insertModule" is
> not in it.
> 
> Make sure you have the sqlmap that contains the "insertModule"
> statement in your SqlMapConfig.xml file.
> 
> Larry
> 
> On Mon, 21 Feb 2005 04:28:08 +0000, Tim Christopher
> <ti...@gmail.com> wrote:
> > Hi,
> >
> > I'm in the middle of incorporating iBATIS into my Struts project, but
> > am having slight trouble in getting it to work.
> >
> > The problem starts when I call sqlMap.startTransaction() from within
> > my BaseDAO file as I get a null pointer exception...  Yet when I print
> > out the value of sqlMap I get something like
> > "com.ibatis.sqlmap.engine.impl.SqlMapClientImpl@1d8c528" - not null as
> > I would have expected given the null pointer error.  Sadly I do not
> > know of any methods I can call that show the state of the sqlMap.
> >
> > Having made various small alterations to the code to try and get it to
> > work I eventually tried removing the line to start the transaction...
> > However this resulted in the following error:
> >
> > com.ibatis.sqlmap.client.SqlMapException: There is no statement named
> > insertModule in this SqlMap.
> >     ...SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:288)
> >     ...SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:491)
> >     ...SqlMapSessionImpl.update(SqlMapSessionImpl.java:89)
> >     ...SqlMapClientImpl.update(SqlMapClientImpl.java:61)
> >     ...com.xyz.BaseDAO.update(BaseDAO.java:101)
> >     <snip/>
> >
> > This leaves me at a point where I'm not certain if this means there is
> > a problem with my XML config file (ie. it's looking, but can't find
> > the statement), or if it looking in an empty object - though I'm
> > guessing (hoping) that fixing the first null pointer error should make
> > it all work fine.
> >
> > Any help / suggestions apreciated.
> >
> > Tim Christopher
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and iBATIS

Posted by Larry Meadors <la...@gmail.com>.
The code there is:

===
    MappedStatement ms = (MappedStatement) mappedStatements.get(id);
    if (ms == null) {
      throw new SqlMapException("There is no statement named " + id +
" in this SqlMap.");
    }
    return ms;
===

Looks like you have a sqlmap, but that the statement "insertModule" is
not in it.

Make sure you have the sqlmap that contains the "insertModule"
statement in your SqlMapConfig.xml file.

Larry

On Mon, 21 Feb 2005 04:28:08 +0000, Tim Christopher
<ti...@gmail.com> wrote:
> Hi,
> 
> I'm in the middle of incorporating iBATIS into my Struts project, but
> am having slight trouble in getting it to work.
> 
> The problem starts when I call sqlMap.startTransaction() from within
> my BaseDAO file as I get a null pointer exception...  Yet when I print
> out the value of sqlMap I get something like
> "com.ibatis.sqlmap.engine.impl.SqlMapClientImpl@1d8c528" - not null as
> I would have expected given the null pointer error.  Sadly I do not
> know of any methods I can call that show the state of the sqlMap.
> 
> Having made various small alterations to the code to try and get it to
> work I eventually tried removing the line to start the transaction...
> However this resulted in the following error:
> 
> com.ibatis.sqlmap.client.SqlMapException: There is no statement named
> insertModule in this SqlMap.
>     ...SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:288)
>     ...SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:491)
>     ...SqlMapSessionImpl.update(SqlMapSessionImpl.java:89)
>     ...SqlMapClientImpl.update(SqlMapClientImpl.java:61)
>     ...com.xyz.BaseDAO.update(BaseDAO.java:101)
>     <snip/>
> 
> This leaves me at a point where I'm not certain if this means there is
> a problem with my XML config file (ie. it's looking, but can't find
> the statement), or if it looking in an empty object - though I'm
> guessing (hoping) that fixing the first null pointer error should make
> it all work fine.
> 
> Any help / suggestions apreciated.
> 
> Tim Christopher
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org