Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 73404 invoked from network); 22 Apr 2010 07:31:21 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Apr 2010 07:31:21 -0000 Received: (qmail 11616 invoked by uid 500); 22 Apr 2010 07:31:21 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 11405 invoked by uid 500); 22 Apr 2010 07:31:19 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 11398 invoked by uid 99); 22 Apr 2010 07:31:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Apr 2010 07:31:18 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of selva.andre@gmail.com designates 209.85.218.215 as permitted sender) Received: from [209.85.218.215] (HELO mail-bw0-f215.google.com) (209.85.218.215) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Apr 2010 07:31:12 +0000 Received: by bwz7 with SMTP id 7so8304887bwz.36 for ; Thu, 22 Apr 2010 00:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:received:message-id :subject:from:to:content-type; bh=jknGkFamZlkKPL+dU1bquGJMHOH0Gi7oNA89pnJxsb4=; b=Il+3E7IzRxETFyU6JbDRLIo0JlSompsteRWrwdMDbHlTB4C7PJfBv/WrEZ+1+8EkBU 08VwkOZhUQw2MNkB9nHOhZCcrem7uYzT9AMPRR4zG+0sOQNFXRlFTncx1DAyqz+ugzIt 6TGFrFdfbpKDXoWjvhFc86gE5up7jJ6aunOjA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=VoeY+tWElsTiVe1Iy+dxrJ5h0BPfLAJLCZkwBOAyulIO6BGhkRcbuTeuvcbnZqfoD1 g+G05gqJZ3Xdlnr/w8N+dQz7qE6twuckFADwhVRyUSYMwDdjs3RKjRVV/CRzVQ8HF+ma QExGs+pNLW5Q0NFdSrRy0iQ6bp8AG4audLEB8= MIME-Version: 1.0 Received: by 10.103.219.11 with HTTP; Thu, 22 Apr 2010 00:30:49 -0700 (PDT) Date: Thu, 22 Apr 2010 09:30:49 +0200 Received: by 10.102.174.35 with SMTP id w35mr2004167mue.51.1271921450017; Thu, 22 Apr 2010 00:30:50 -0700 (PDT) Message-ID: Subject: Problem with id mapping to IDENTITY in HSQLDB From: Andrea Selva To: user-java@ibatis.apache.org Content-Type: multipart/alternative; boundary=0016364c74df35e4200484ce4a7b --0016364c74df35e4200484ce4a7b Content-Type: text/plain; charset=ISO-8859-1 Hi list, i've a trouble with IDENTITY in hsqldb and id attribute in a resulMap: --- Activity DDL ---- DROP TABLE Activity; CREATE TABLE Activity ( idActivity IDENTITY, name varchar(30) not null, description varchar(100) null, constraint pk_activity primary key (idActivity) ); ----ResultMap --------- NB Activity is an alias for the class i map --- This is my mapper annotated interface ----- public interface ActivityMapper { @Select("SELECT * FROM Activity") List listAll(); } --- My domain class ---- public class Activity implements Serializable { private static final long serialVersionUID = -4735861071294335763L; private int id = -55; //only for test private String name; private String description; public Activity(String name, String description) { this.name = name; this.description = description; } public Activity() {} public int getId() { return id; } public String getDescription() { return description; } public String getName() { return name; } public int getDays() { return days; } } --- This is the test incriminate test code --- @Test public void testAllActivities() throws SQLException, IOException { Activity activity1 = new Activity("Fake Name", "Fake description"); Activity activity2 = new Activity("Fake Name 2", "Second fake description"); IActivityDAO dao = new IBatisActivityDAO(); dao.addNewActivity(activity1); dao.addNewActivity(activity2); DBUtils.printQueryResults("SELECT * FROM Activity"); Reader reader = Resources.getResourceAsReader("org/dna/metronomo/persistence/configuration.xml"); SqlSessionFactory m_sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); ActivityMapper mapper = m_sqlSessionFactory.openSession().getMapper(ActivityMapper.class); List activities = mapper.listAll(); assertEquals(2, activities.size()); assertEquals(activity1.getName(), activities.get(0).getName()); assertEquals(0, activities.get(0).getId()); assertEquals(activity2.getName(), activities.get(1).getName()); assertEquals(1, activities.get(1).getId()); } When I load the list of activities I find correctly populated all attributes except the key attribute, the id, i discover that the mapper doesn't fill it with the correct value from DB (a SELECT on the DB shot that the data are presents) but put the -55 default value that I set. I can't understand why IBatis 3 doesn't corretly map the key IDENTITY column to the java attribute. The iBAtis3 svn rev I use is r928229. Many thanks in advance for any usefull hint. Best regards Andrea Selva --0016364c74df35e4200484ce4a7b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi list,
i've a trouble with IDENTITY in hsqldb and id attribute in = a resulMap:

--- Activity DDL ----
DROP TABLE Activity;

CRE= ATE TABLE Activity (
=A0=A0=A0 idActivity IDENTITY,
=A0=A0=A0 name va= rchar(30) not null,
=A0=A0=A0 description varchar(100) null,
=A0=A0=A0 constraint pk_activit= y primary key (idActivity)
);

----ResultMap ---------
<resu= ltMap id=3D"activityResultMap" type=3D"Activity">=A0=A0=A0 <id property=3D"id" column=3D"idActivity"= />
=A0=A0=A0 <result property=3D"name" column=3D"name" = />
=A0=A0=A0 <result property=3D"description" column=3D&= quot;description" />
</resultMap>

NB Activity is an= alias for the class i map

--- This is my mapper annotated interface -----
public interface Act= ivityMapper {
=A0=A0=A0 @Select("SELECT * FROM Activity")
= =A0=A0=A0 List<Activity> listAll();
}


--- My domain cla= ss ----
public class Activity implements Serializable {
=A0=A0=A0 private static= final long serialVersionUID =3D -4735861071294335763L;
=A0=A0=A0 privat= e int id =3D -55; //only for test
=A0=A0=A0 private String name;
=A0= =A0=A0 private String description;

=A0=A0=A0 public Activity(String name, String description) {
=A0=A0= =A0 =A0=A0=A0 this.name =3D name;
=A0= =A0=A0 =A0=A0=A0 this.description =3D description;
=A0=A0=A0 }
=A0=A0= =A0
=A0=A0=A0 public Activity() {}

=A0=A0=A0 public int getId() = {
=A0=A0=A0 =A0=A0=A0 return id;
=A0=A0=A0 }

=A0=A0=A0 public Strin= g getDescription() {
=A0=A0=A0 =A0=A0=A0 return description;
=A0=A0= =A0 }

=A0=A0=A0 public String getName() {
=A0=A0=A0 =A0=A0=A0 ret= urn name;
=A0=A0=A0 }

=A0=A0=A0 public int getDays() {
=A0=A0= =A0 =A0=A0=A0 return days;
=A0=A0=A0 }
}


--- This is the test incriminate test code ---<= br>
@Test
=A0=A0=A0 public void testAllActivities() throws SQLExcepti= on, IOException {
=A0=A0=A0 =A0=A0=A0 Activity activity1 =3D new Activit= y("Fake Name", "Fake description");
=A0=A0=A0 =A0=A0=A0 Activity activity2 =3D new Activity("Fake Name 2&q= uot;, "Second fake description");
=A0=A0=A0 =A0=A0=A0 IActivit= yDAO dao =3D new IBatisActivityDAO();
=A0=A0=A0 =A0=A0=A0 dao.addNewActi= vity(activity1);
=A0=A0=A0 =A0=A0=A0 dao.addNewActivity(activity2);
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 DBUtils.printQueryResults("= ;SELECT * FROM Activity");
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0= =A0 Reader reader =3D Resources.getResourceAsReader("org/dna/metronomo= /persistence/configuration.xml");
=A0=A0=A0 =A0=A0=A0 SqlSessionFac= tory m_sqlSessionFactory =3D new SqlSessionFactoryBuilder().build(reader);<= br> =A0=A0=A0 =A0=A0=A0 ActivityMapper mapper =3D m_sqlSessionFactory.openSessi= on().getMapper(ActivityMapper.class);
=A0=A0=A0 =A0=A0=A0 List<Activi= ty> activities =3D mapper.listAll();
=A0=A0=A0 =A0=A0=A0 assertEquals= (2, activities.size());
=A0=A0=A0 =A0=A0=A0 assertEquals(activity1.getNa= me(), activities.get(0).getName());
=A0=A0=A0 =A0=A0=A0 assertEquals(0, activities.get(0).getId());
=A0=A0= =A0 =A0=A0=A0 assertEquals(activity2.getName(), activities.get(1).getName()= );
=A0=A0=A0 =A0=A0=A0 assertEquals(1, activities.get(1).getId());
= =A0=A0=A0 }

When I load the list of activities I find correctly popu= lated all attributes except the key attribute, the id, i discover that the = mapper doesn't fill it with the correct value from DB (a SELECT on the = DB shot that the data are presents) but put the -55 default value that I se= t.
I can't understand why IBatis 3 doesn't corretly map the key IDENTI= TY column to the java attribute.
The iBAtis3 svn rev I use is r928229.Many thanks in advance for any usefull hint.
=A0Best regards
=A0 A= ndrea Selva

--0016364c74df35e4200484ce4a7b--