java - MyBatis - One to many - values not set for mapped column -
i using mybatis access database. purpose have following classes:
class classa { private int id; private list<classb> list; // public getters , setters } class classb { private int id; // public getters , setters }
the according daos that:
public interface classadao { @select("select id, name, description tablea id = #{id}") @results( @result(property = "list", javatype = list.class, column = "id", many = @many(select = "classbdao.getclassbforclassa"))) classa getclassabyid(@param("id") long id); } public interface classbdao { @select("select id, classaid tableb classaid = #{id}") classb getclassbforclassa(@param("id") long id); }
unfortunately id column of classa
not filled correct id. seems because used mapped column.
anyone experienced problem or has solution? renaming of columns not far can see it, because still mapped column , consequence value not set.
i able track down in mybatis code think: org.apache.ibatis.executor.resultset.defaultresultsethandler#applyautomaticmappings()
apply mappings unmapped columns.
i found solution may struggle same problem in future. strangely have specify id column additional result (as mapped):
public interface classadao { @select("select id, name, description tablea id = #{id}") @results({@result(property = "id", column = "id"), @result(property = "list", javatype = list.class, column = "id", many = @many(select = "classbdao.getclassbforclassa"))}) classa getclassabyid(@param("id") long id); }
Comments
Post a Comment