google-code-export / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

Using many-to-many mapping with Map #597

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi All,

Let's say a POJO Is

public class Class1 {
           private String abc;
           private String def;
           private List<Class2> list;
}
then, we can have below annotations to fetch Class1 along with list
field.
@Result(property="list", javaType=List.class,
column="abc",many=@Many(select="getClass2"))

where getClass2 method returns list of Class2 and join is column 'abc'
List<Class2> getClass2(String abc);

My use case is slightly different
public class Class1 {
           private String abc;
           private String def;
           private Map<Sting, Class2> map;
}

So, is this possible using annotations ?
If yes, what changes should be done ?

What I am trying is

@MapKey("abc")
Map<String, Class2> getClass2(String abc);

@Result(property="map", javaType=Map.class,
column="abc",many=@Many(select="getClass2"))

This is giving me below exceptio
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause:
org.apache.ibatis.executor.ExecutorException: Statement getClass2
returned more than one row, where no more than one was expected.

//Apology, if this is not the right place for this mail

Original issue reported on code.google.com by shoonya....@gmail.com on 16 May 2012 at 7:09

GoogleCodeExporter commented 9 years ago
Hi Shoonya. Please use the mailing list for questions. Thank you!

http://groups.google.com/group/mybatis-user

Original comment by eduardo.macarron on 16 May 2012 at 5:37