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 Co...@courts.mo.gov on 2006/12/13 16:03:21 UTC

spring newbie having problems using ibatis with spring dao

Hi,
  I noticed that the website now recommends using the spring dao framework
instead of the ibatis one.
I have never used spring before and decided to try a little test to see how
to get the spring dao
framework up and running with ibatis. I am using spring 2.01 and have tried
ibatis 2.1.7.597,
2.2.0.638 and 2.3.0.677 but still get the following error. According to the
log it looks like
an ">" is getting inserted into my sql statement somewhere in the process.
Is there something in my
spring files that is causing this? Any ideas?

Thanks,
Cory


.
error -
2006-12-13 08:38:40,551 INFO [org.springframework.core.CollectionFactory] -
<JDK 1.4+ collections available>
2006-12-13 08:38:40,598 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading
XML bean definitions from class path resource [beans.xml]>
2006-12-13 08:38:41,804 DEBUG [java.sql.Connection] - <{conn-100000}
Connection>
2006-12-13 08:38:42,039 DEBUG [java.sql.PreparedStatement] - <{pstm-100001}
PreparedStatement:      SELECT * FROM OTOT_JOB_SCHEDULE   >
2006-12-13 08:38:42,039 DEBUG [java.sql.PreparedStatement] - <{pstm-100001}
Parameters: []>
2006-12-13 08:38:42,039 DEBUG [java.sql.PreparedStatement] - <{pstm-100001}
Types: []>
2006-12-13 08:38:42,071 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading
XML bean definitions from class path resource
[org/springframework/jdbc/support/sql-error-codes.xml]>
2006-12-13 08:38:42,180 INFO
[org.springframework.jdbc.support.SQLErrorCodesFactory] - <SQLErrorCodes
loaded: [DB2, Derby, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL,
Sybase]>
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException:
SqlMapClient operation; bad SQL grammar []; nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in test/OtotJobSchedule.xml.
--- The error occurred while applying a parameter map.
--- Check the OtotJobSchedule.getAll-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORA-00942: table or view does not exist

beans.xml -
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
  <bean id="ototJobScheduleDao" class="test.SqlMapOtotJobScheduleDao">
    <property name="sqlMapClient" ref="sqlMapClient" />
  </bean>
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
    <property name="driverClassName" value=
"oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@hostname:1521:sid" />
    <property name="username" value="username" />
    <property name="password" value="password" />
  </bean>
  <bean id="sqlMapClient" class=
"org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation" value="test/sql-map-config.xml"/>
    <property name="dataSource" ref="dataSource"/>
  </bean>
</beans>

sql-map-config.xml -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
  "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
  <settings
    useStatementNamespaces="true"
    cacheModelsEnabled="true"
    enhancementEnabled="true"/>
  <sqlMap resource="test/OtotJobSchedule.xml" />
</sqlMapConfig>

OtotJobSchedule.xml -
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
  "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="OtotJobSchedule">
  <resultMap id="result" class="test.OtotJobSchedule">
    <result property="id" column="ID" columnIndex="1"/>
    <result property="description" column="DESCRIPTION" columnIndex="2"/>
    <result property="cron" column="CRON" columnIndex="3"/>
    <result property="jobType" column="JOB_TYPE" columnIndex="4"/>
    <result property="param" column="PARAM" columnIndex="5"/>
    <result property="active" column="ACTIVE" columnIndex="6"/>
  </resultMap>
  <select id="getAll" resultMap="result">
    SELECT * FROM OTOT_JOB_SCHEDULE
  </select>
</sqlMap>

Main.java -
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Iterator;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import test.OtotJobSchedule;
import test.OtotJobScheduleDao;

public class Main {
  public static void main(String[] args) {
    ClassPathResource resource = new ClassPathResource("beans.xml");
    BeanFactory beanFactory = new XmlBeanFactory(resource);
    OtotJobScheduleDao ototJobScheduleDao = (OtotJobScheduleDao)
beanFactory
        .getBean("ototJobScheduleDao");
    List list = ototJobScheduleDao.getAll();
    for (Iterator iterator = list.iterator(); iterator.hasNext();) {
      OtotJobSchedule ototJobSchedule = (OtotJobSchedule) iterator.next();
      System.out.println(ototJobSchedule.getId() + ":"
          + ototJobSchedule.getDescription() + ":"
          + ototJobSchedule.getJobType());
    }
  }
}



Cory Bestgen
Information Technology Division
Office of State Courts Administrator
(573) 522 - 5455
cory.bestgen@courts.mo.gov


Re: spring newbie having problems using ibatis with spring dao

Posted by Co...@courts.mo.gov.
Yes; it was my fault. I didn't specify the schema in the query.
For some reason I got hung up on that trailing ">" in the log message
instead of paying attention to the cause.


Cory Bestgen
Information Technology Division
Office of State Courts Administrator
(573) 522 - 5455
cory.bestgen@courts.mo.gov


                                                                           
             "Brandon Goodin"                                              
             <brandon.goodin@g                                             
             mail.com>                                                  To 
                                       user-java@ibatis.apache.org         
             12/13/2006 10:15                                           cc 
             AM                                                            
                                                                   Subject 
                                       Re: spring newbie having problems   
             Please respond to         using ibatis with spring dao        
             user-java@ibatis.                                             
                apache.org                                                 
                                                                           
                                                                           
                                                                           
                                                                           




Generally it is good etiquette to explain what you did to fix the problem.
This allows others to glean knowledge from your experiences...even if it
was an error on your side.

Cheers,
Brandon

On 12/13/06, Cory.Bestgen@courts.mo.gov <Co...@courts.mo.gov> wrote:
  Sorry, found the problem.


  Cory Bestgen
  Information Technology Division
  Office of State Courts Administrator
  (573) 522 - 5455
  cory.bestgen@courts.mo.gov



               Cory.Bestgen@cour
               ts.mo.gov

  To
               12/13/2006 09:04           user-java@ibatis.apache.org
               AM
  cc


  Subject
               Please respond to         spring newbie having problems
  using
               user-java@ibatis.         ibatis with spring dao
                  apache.org










  Hi,
    I noticed that the website now recommends using the spring dao
  framework
  instead of the ibatis one.
  I have never used spring before and decided to try a little test to see
  how
  to get the spring dao
  framework up and running with ibatis. I am using spring 2.01 and have
  tried
  ibatis 2.1.7.597,
  2.2.0.638 and 2.3.0.677 but still get the following error. According to
  the
  log it looks like
  an ">" is getting inserted into my sql statement somewhere in the
  process.
  Is there something in my
  spring files that is causing this? Any ideas?

  Thanks,
  Cory





  Cory Bestgen
  Information Technology Division
  Office of State Courts Administrator
  (573) 522 - 5455
  cory.bestgen@courts.mo.gov






Re: spring newbie having problems using ibatis with spring dao

Posted by Brandon Goodin <br...@gmail.com>.
Generally it is good etiquette to explain what you did to fix the problem.
This allows others to glean knowledge from your experiences...even if it was
an error on your side.

Cheers,
Brandon

On 12/13/06, Cory.Bestgen@courts.mo.gov <Co...@courts.mo.gov> wrote:
>
> Sorry, found the problem.
>
>
> Cory Bestgen
> Information Technology Division
> Office of State Courts Administrator
> (573) 522 - 5455
> cory.bestgen@courts.mo.gov
>
>
>
>              Cory.Bestgen@cour
>              ts.mo.gov
>                                                                         To
>              12/13/2006 09:04          user-java@ibatis.apache.org
>              AM                                                         cc
>
>                                                                    Subject
>              Please respond to         spring newbie having problems using
>              user-java@ibatis.         ibatis with spring dao
>                 apache.org
>
>
>
>
>
>
>
>
>
>
> Hi,
>   I noticed that the website now recommends using the spring dao framework
> instead of the ibatis one.
> I have never used spring before and decided to try a little test to see
> how
> to get the spring dao
> framework up and running with ibatis. I am using spring 2.01 and have
> tried
> ibatis 2.1.7.597,
> 2.2.0.638 and 2.3.0.677 but still get the following error. According to
> the
> log it looks like
> an ">" is getting inserted into my sql statement somewhere in the process.
> Is there something in my
> spring files that is causing this? Any ideas?
>
> Thanks,
> Cory
>
>
>
>
>
> Cory Bestgen
> Information Technology Division
> Office of State Courts Administrator
> (573) 522 - 5455
> cory.bestgen@courts.mo.gov
>
>
>
>

Re: spring newbie having problems using ibatis with spring dao

Posted by Co...@courts.mo.gov.
Sorry, found the problem.


Cory Bestgen
Information Technology Division
Office of State Courts Administrator
(573) 522 - 5455
cory.bestgen@courts.mo.gov


                                                                           
             Cory.Bestgen@cour                                             
             ts.mo.gov                                                     
                                                                        To 
             12/13/2006 09:04          user-java@ibatis.apache.org         
             AM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         spring newbie having problems using 
             user-java@ibatis.         ibatis with spring dao              
                apache.org                                                 
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           





Hi,
  I noticed that the website now recommends using the spring dao framework
instead of the ibatis one.
I have never used spring before and decided to try a little test to see how
to get the spring dao
framework up and running with ibatis. I am using spring 2.01 and have tried
ibatis 2.1.7.597,
2.2.0.638 and 2.3.0.677 but still get the following error. According to the
log it looks like
an ">" is getting inserted into my sql statement somewhere in the process.
Is there something in my
spring files that is causing this? Any ideas?

Thanks,
Cory





Cory Bestgen
Information Technology Division
Office of State Courts Administrator
(573) 522 - 5455
cory.bestgen@courts.mo.gov