Thanks for the reply Clinton. Using annotations implicitly drives my mind to ORM. Is there a way to say that an @Select annotation could be linked to a resultMap defined in th XML? Else i think that i have to replicate the resultMap in annotation syntahx with (@Results and @Result) or that i have to remove the annotated method and use only the xml. I'm think to something @Select("query="SELECT * FROM Activity", map=<ResultMap name>) public List<Activity> allActivities();
Many thanks, Andrea Selva On Thu, Apr 22, 2010 at 3:18 PM, Clinton Begin <clinton.be...@gmail.com>wrote: > There's currently no way to use an xml result map from an annotation. > Remember, ibatis is not an ORM, so you have to pair result maps with > statements each time, and currently the entire pair must be xml or > annotations. > > On 2010-04-22, Andrea Selva <selva.an...@gmail.com> wrote: > > 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 > > > > -- > Sent from my mobile device > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org > For additional commands, e-mail: user-java-h...@ibatis.apache.org > >