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 Giovanni D'Addabbo <gi...@gmail.com> on 2007/05/31 09:53:42 UTC

No Statement...

Hi all
i'm new to Ibatis and i'm reading "Ibatis in action" Book but i've a No
statetement problem...
so i've these files:

sqlMapConfig.xml
---
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config
2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd ">

<sqlMapConfig>

     <properties resource="com/magoscuro/ibatis/dati.properties"/>

     <transactionManager type="JDBC" >
         <dataSource type="SIMPLE">
             <property name="JDBC.Driver" value="${driver}"/>
             <property name="JDBC.ConnectionURL" value="${url}"/>
             <property name=" JDBC.Username" value="${user}"/>
             <property name="JDBC.Password" value="${password}"/>
         </dataSource>
     </transactionManager>

     <sqlMap resource="com/magoscuro/ibatis/SqlMap.xml" />

</sqlMapConfig>
---

SqlMap.xml
---
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0 //EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap>

     <select id="getAllAccountIdValue" resultClass="int">
         select count(USERID) from USER_ACCOUNT
     </select>

     <select id="getAllUsers" parameterClass="string" resultClass="hashmap">
     SELECT * FROM USER_ACCOUNT WHERE GROUPNAME = #groupName#
     </select>

</sqlMap>
---

and finally my java file:

---
     public static void main(String[] args) throws Exception {

         String resource = "com/magoscuro/ibatis/SqlMapConfig.xml";
         Reader reader = Resources.getResourceAsReader(resource);
         SqlMapClient sqlMap = 
SqlMapClientBuilder.buildSqlMapClient(reader);
         List list = sqlMap.queryForList("getAllUsers","EMPLOYEE");

         System.out.println("Selected " + list.size() + " records");

         for (int i=0; i<list.size(); i++){
             System.out.println(list.get(i));
         }

     }
---

Ok it work very well but i've read in the book that i can use dot
notation, for example Account.gettAllUsers ok now is the problem...how
can i use this dot notation? :D

thank in advance
-- 
Giovanni D'Addabbo
http://www.magoscuro.com

Re: No Statement...

Posted by Graeme J Sweeney <ib...@gjsweeney.com>.
On Thu, 31 May 2007, Giovanni D'Addabbo wrote:

<snip/>

> Ok it work very well but i've read in the book that i can use dot
> notation, for example Account.gettAllUsers ok now is the problem...how
> can i use this dot notation? :D

IIUC, you need to enable namespaces:

<sqlMapConfig>
...
   <settings
     useStatementNamespaces="true"
     />
...
<sqlMapConfig>


<sqlMap namespace="Account">
...

     <select id="getAllAccountIdValue" resultClass="int">
         select count(USERID) from USER_ACCOUNT
     </select>
...
  </sqlMap>


-- 
Graeme -

RE: No Statement...

Posted by Meindert <me...@pastelebusiness.com>.
Let me start by saying that I don't have the book, and I don't understand
your question..

Anyway I like the 'feature' of IBATIS that I can map a join query to objects
and child objects using 'dot notation'

 

Example;

 

I've got a domain class called Declaration, in it is a other domain class
with the name employee of the type EmplMain, 

This must be mapped to table Declaration joined to table EmplMain

 

Step 1;

Create the empty employee domain object  in the declaration class

public Declaration() {

        employee = new EmpName();

}

 

Step 2;

The sql map. Beware of case sensitivity and the fact that even when you
select something like EmplMain.NickName the result column is most likely to
be just NickName.

Therefore you would have to select it like EmplMain.NickName as
'EmplMain.NickName'

 

<typeAlias alias="declaration" type="com.pastel.ess.domain.Declaration"/>

 

<statement id="getDeclaration" resultClass="declaration" >

        SELECT Declaration.*, 

        EmplMain.EmplName as 'employee.emplName', EmplMain.Surname as
'employee.surname',

        EmplMain.NickName as 'employee.nickName', EmplMain.Code as
'employee.code',

        EmplMain.Email as 'employee.email', ..

        FROM Declaration ..

 

 

-----Original Message-----
From: Giovanni D'Addabbo [mailto:giovanni.daddabbo@gmail.com] 
Sent: 31 May 2007 09:54 AM
To: user-java@ibatis.apache.org
Subject: No Statement...

 

Hi all

i'm new to Ibatis and i'm reading "Ibatis in action" Book but i've a No

statetement problem...

so i've these files:

 

sqlMapConfig.xml

---

<?xml version="1.0" encoding="UTF-8"?>

 

<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config

2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd ">

 

<sqlMapConfig>

 

     <properties resource="com/magoscuro/ibatis/dati.properties"/>

 

     <transactionManager type="JDBC" >

         <dataSource type="SIMPLE">

             <property name="JDBC.Driver" value="${driver}"/>

             <property name="JDBC.ConnectionURL" value="${url}"/>

             <property name=" JDBC.Username" value="${user}"/>

             <property name="JDBC.Password" value="${password}"/>

         </dataSource>

     </transactionManager>

 

     <sqlMap resource="com/magoscuro/ibatis/SqlMap.xml" />

 

</sqlMapConfig>

---

 

SqlMap.xml

---

<?xml version="1.0" encoding="UTF-8"?>

 

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0 //EN"

"http://ibatis.apache.org/dtd/sql-map-2.dtd">

 

<sqlMap>

 

     <select id="getAllAccountIdValue" resultClass="int">

         select count(USERID) from USER_ACCOUNT

     </select>

 

     <select id="getAllUsers" parameterClass="string" resultClass="hashmap">

     SELECT * FROM USER_ACCOUNT WHERE GROUPNAME = #groupName#

     </select>

 

</sqlMap>

---

 

and finally my java file:

 

---

     public static void main(String[] args) throws Exception {

 

         String resource = "com/magoscuro/ibatis/SqlMapConfig.xml";

         Reader reader = Resources.getResourceAsReader(resource);

         SqlMapClient sqlMap = 

SqlMapClientBuilder.buildSqlMapClient(reader);

         List list = sqlMap.queryForList("getAllUsers","EMPLOYEE");

 

         System.out.println("Selected " + list.size() + " records");

 

         for (int i=0; i<list.size(); i++){

             System.out.println(list.get(i));

         }

 

     }

---

 

Ok it work very well but i've read in the book that i can use dot

notation, for example Account.gettAllUsers ok now is the problem...how

can i use this dot notation? :D

 

thank in advance

-- 

Giovanni D'Addabbo

http://www.magoscuro.com