title: Mybatis Generator: What's the best way to separate out "auto generated" and "hand edited files"
body: <p>I am on a project that uses both <em>Mybatis</em> (for persisting java to database) and <em>Mybatis Generator</em> (to automatically generate the mapper xml files and java interfaces from a database schema). </p>
  
  <p>Mybatis generator does a good job at generating the files necessary for basic crud operation.</p>
  
  <p><strong>Context</strong></p>
  
  <p>For some of the tables/classes, we will need more "stuff" (code queries, etc) than the "crud stuff" generated by the MyBatis Generator tool. </p>
  
  <p>Is there any way to have "best of both worlds", i.e use auto generation as as well as "custom code". How do you separate out and structure the "hand edited files" and "automatically generated files". </p>
  
  <p><strong>Proposal</strong></p>
  
  <p>I was thinking about the following,  i.e. for table "Foo"</p>
  
  <p><em>Auto-Generated</em></p>
  
  <ul>
  <li>FooCrudMapper.xml </li>
  <li>interface FooCrud.java</li>
  </ul>
  
  <p>(where "Crud" stands for "Create Read Update Delete")</p>
  
  <p><em>Hand Edited</em></p>
  
  <ul>
  <li>FooMapper.xml</li>
  <li>interface Foo extends FooCrud</li>
  </ul>
  
  <p>The notion: if the schema changed, you could always safely autogenerate the "Crud" xml and .java files without wiping out any of the custom changes.</p>
  
  <p><strong>Questions</strong></p>
  
  <ul>
  <li><p>Would mybatis correctly handle this scenario, i.e. would this mapper correctly execute the auto-generated 'crud code'?</p>
  
  <p>FooMapper fooMapper = sqlSession.getMapper(FooMapper.class);</p></li>
  <li><p>What approach do you recommend?</p></li>
  </ul>
  
  <p>Edit 1:
  * Our db design uses a 'core table' ("element") with other tables 'extending' that table and adding extra attributes (shared key) . I've looked at docs and source concluded that I cannot use Mybatis Generator in conjunction with such 'extension' without any hand editing:</p>
  
  <p>i.e. This does not work.
   -ElementMapper extends "ElementCrudMapper"
   -FooMapper.xml extends both "ElementCrudMapper" and "FooCrudMapper"</p>
  
  <p>thanks all!</p>