8

Has MyBatis any feature to allow create the SQL schema from de Class Model like Hibernate does?

I'm looking for that in Google and I only found information about MyBatis Generator (http://mybatis.github.io/generator/). This tool seems to be useful for generate the Java model from the SQL Schema, which is just the opposite I want.

Sergio Trapiello
  • 718
  • 9
  • 18
  • MyBatis can't do this, but the tool you used to create the class diagram should have this capability. – kiwiron Aug 16 '14 at 22:30

2 Answers2

10

Can MyBatis create the database schema?

I'm afraid not. In order to do that you need an ORM and MyBatis is not an ORM.

With an ORM solution (like Hibernate for example) you map tables to entities. The entity is the (object) representation of the (relational) table and contains all the metadata (getters/setters, annotations etc) necessary to create the table.

MyBatis does not map entities to tables, it maps methods to SQL statements. There is no way to determine from the methods or the SQL statements what the structure of the database should be. When you use MyBatis the tables must already exist.

Bogdan
  • 23,890
  • 3
  • 69
  • 61
  • thanks, is what I meant. I normally use Hibernate and I wonder if MyBatis has that feature too. – Sergio Trapiello Aug 19 '14 at 13:14
  • Thanks @bogdan. I was looking out for the same answer. Can you please justify for one thing i.e. **MyBatis is not an ORM**. Because from most of people, I heard MyBatis as second ORM ! – Aman Gupta Nov 21 '14 at 11:15
  • 2
    @agpt: It all depends on what you understand by ORM. For some people an ORM is anything that bridges the gap between objects and a database, so from that respect MyBatis, to them, is an ORM. My definition of an ORM is stronger. It's a tool that tries to fool you in thinking there is no database, that you work only with objects and object graphs and then some magic fairy persists them somewhere. It also handles (and hides) the SQL for you. For some applications all of this works, [for others it doesn't](http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch)... – Bogdan Nov 22 '14 at 20:05
  • 2
    ...MyBatis on the other hand does nothing of the sort. With MyBatis the database is there, in your face. You don't want to deal with SQL? Too bad... you have to! MyBatis doesn't generate anything for you, it just takes care of all that boiler plate code needed to get your data out and into the database. MyBatis doesn't have the features of an ORM, it's just a data mapper. – Bogdan Nov 22 '14 at 20:06
0

I tried create a new database schema and new table via the mybatis, it works well with my mysql db. So it seems mybatis totally support the execution almost all of the free sql statement.

I think you could refer another answer.

Creating a table programmatically using MyBatis and MySql

Greatvia
  • 155
  • 1
  • 11