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 ---------
<resultMap id="activityResultMap" type="Activity">
<id property="id" column="idActivity" />
<result property="name" column="name" />
<result property="description" column="description" />
</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<Activity> 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<Activity> 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