2

I have three tables:

  1. table ONE pk:ONE.ID
  2. table TWO fk:TWO.ID with ONE.ID pk:TWO.ID TWO.FIELD
  3. table THREE fk:TWO.ID with THREE.ID and TWO.FIELD=THREE.FIELD

Is it possible to set the join in the xml configuration, and let mybatis to generate the classes and methods with the join?

Thanks.

michele
  • 26,348
  • 30
  • 111
  • 168
  • Same question here, I'm doing something similar. Table 1 -> employee -> pk_employee; Table 2 -> doctor -> fk_employee; I want doctor to be a subclass of employee. And I get it by using the property rootclass in the mybatis generator xml config. `` But the only thing it does is that Doctor class inherits from Employee but with nothing similar to a joing working. If I query a list of doctors, I get a list of doctor/employees with all the employee fields empty. – JFValdes Feb 09 '18 at 11:45

1 Answers1

2

MyBatis Generator does not generate code for joins.

However, the "MyBatis Dynamic SQL" library has support for joins. You could use MyBatis Generator to generate the basic CRUD operations for the tables, then add the joins yourself. Just set <context targetRuntime="MyBatis3DynamicSql">

There is information on this page regarding joins in the library: http://www.mybatis.org/mybatis-dynamic-sql/docs/select.html

Jeff Butler
  • 991
  • 6
  • 11