Can MyBatis create the database schema?
Asked Answered
C

2

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.

Chellman answered 13/8, 2014 at 9:20 Comment(1)
MyBatis can't do this, but the tool you used to create the class diagram should have this capability.Depressed
E
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.

Estray answered 16/8, 2014 at 20:36 Comment(4)
thanks, is what I meant. I normally use Hibernate and I wonder if MyBatis has that feature too.Chellman
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 !Elder
@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...Estray
...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.Estray
H
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

Horseplay answered 8/2, 2021 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.