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 David Evans <ds...@berndtgroup.net> on 2008/07/01 20:26:15 UTC

Re: Using Struts with Spring DAO's in IBATIS

I am using Spring DAO and ibatis with struts, without tying the two
together.

I have basically modified the configuration explained here:
http://opensource.atlassian.com/confluence/oss/display/IBATIS/Converting
+iBATIS+DAO+to+Spring+DAO


I have a ServeletContextListener that creates a singleton configuration
object, using Spring to populate its set of variables that hold
references to daos:

public void contextInitialized(ServletContextEvent event) {
  ServletContext servletContext = event.getServletContext();
  this.springContext =
WebApplicationContextUtils.getWebApplicationContext(servletContext);
  CoreApplicationConfig config = CoreApplicationConfig.getInstance();

config.setUserDaoService((UserDAOService)springContext.getBean("userDaoService"));
}


In my action I do this:

ApplicationConfig config = CoreApplicationConfig.getInstance();
UserDAOService userDaoService = config.getUserDaoService();

If I ever want to replace Spring, my struts actions will never know.

Dave



You wrote:
Hi there,
We have an application where we are using Struts as our web framework
and IBATIS in the data layer. We upgraded to the new version of ibatis
which required to upgrade the DAO's to Spring DAO's.

To use the Spring DAO's we started to use spring with struts. The only
purpose of Spring was to inject the dao's into the service classes and
into my Struts Action. However , this approach ties my Struts framework
with Spring. Because, the beans.xml file tries to see Struts Action
classes as Beans to do its injection.

<action-mappings>

        <action
                path="/employeeSetUp"
                name="employeeForm"

                type="org.springframework.web.struts.DelegatingActionProxy"



This approach however, ties Ibatis to Spring and forces us to use Spring
in our web layer as well. 

Can I use Spring DAO's without doing dependency injection?
Has anyone used Ibatis Spring DAO's in Struts without making Struts
aware of the existence of Spring. Any pointers are appreciated.
 


Re: SQLException

Posted by John Chien <jo...@ncmail.net>.
Thanks. I found that is DatabaseAccessException.

Chris O'Connell wrote:
> Are you using Spring?  The Spring SqlMapClientTemplate converts all those
> SQLExceptions into a runtime exception, so your IDE won't see any exception
> that you need to 'catch'.
>
> -----Original Message-----
> From: John Chien [mailto:john.chien@ncmail.net] 
> Sent: Thursday, July 03, 2008 1:33 PM
> To: user-java@ibatis.apache.org
> Subject: SQLException
>
> According to the IBatis Developer Guide, the insert(), update()  ... etc
> will throw SQLException.
>
> However, when I use try and catch block to catch the SQLException, I was
> told that the exception never throws.
>
> What is the real exception throws from those statement ?
>
> Thanks,
>
> John Chien
>
>
>
> No virus found in this incoming message.
> Checked by AVG. 
> Version: 8.0.134 / Virus Database: 270.4.4/1531 - Release Date: 7/2/2008
> 7:02 PM
>
>   

RE: SQLException

Posted by Chris O'Connell <oc...@gorillachicago.com>.
Are you using Spring?  The Spring SqlMapClientTemplate converts all those
SQLExceptions into a runtime exception, so your IDE won't see any exception
that you need to 'catch'.

-----Original Message-----
From: John Chien [mailto:john.chien@ncmail.net] 
Sent: Thursday, July 03, 2008 1:33 PM
To: user-java@ibatis.apache.org
Subject: SQLException

According to the IBatis Developer Guide, the insert(), update()  ... etc
will throw SQLException.

However, when I use try and catch block to catch the SQLException, I was
told that the exception never throws.

What is the real exception throws from those statement ?

Thanks,

John Chien



No virus found in this incoming message.
Checked by AVG. 
Version: 8.0.134 / Virus Database: 270.4.4/1531 - Release Date: 7/2/2008
7:02 PM


SQLException

Posted by John Chien <jo...@ncmail.net>.
According to the IBatis Developer Guide, the insert(), update()  ... etc 
will throw SQLException.

However, when I use try and catch block to catch the SQLException, I was 
told that the exception never throws.

What is the real exception throws from those statement ?

Thanks,

John Chien