1

I have a POJO like this

 public class Application
{
  private String dcn;
  private Party applicant;
  private Date createdDateTime;
  private NamedValue[] flags;
  // containing getter and setters
  }
public class Party
{
  private String lastName;
  private String rfc;
  // containing getter and setters..
  }

And my table columns are..

dcn,applicantLastName,applicantRFC,createdDateTime,flag

all are varchar type. I am using annotations to get data from the above table and set it to POJO using below Query.

@Select("SELECT dcn,applicantLastName,applicantRFC,createdDateTime,flag FROM DnA_Application WHERE dcn=#{dcn}")
  List<Application> getByProc(int proc);

I am not getting data for Party bean from table using above config .Please help.

1 Answer 1

3

There's no way to map the result of the join using annotations. This is not supported in mybatis. Here's a quotation from the documentation:

You will notice that join mapping is not supported via the Annotations API. This is due to the limitation in Java Annotations that does not allow for circular references

One way to do mapping is to define a result map in the xml and reference it via @ResultMap.

mapper.xml:

<resultMap id="ApplicationResultMap" type="Application" autoMapping="true">
   <id property="dcn" column="dcn"  />
   <association property="party" javaType="Party" resultMap="PartyResultMap" columnPrefix="applicant"/>
</resultMap>

In mapper interface:

@Select("SELECT dcn,applicantLastName,applicantRFC,createdDateTime,flag FROM DnA_Application WHERE dcn=#{dcn}")
@ResultMap("ApplicationResultMap")
List<Application> getByProc(int proc);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your reponse .
@AtulSingh, if this answer solves your problem you should formally accept it: see stackoverflow.com/help/someone-answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.