JHipster - Using existing database in Hibernate - mysql

My question is related to use Hibernate into JHipster.
I'd like to know if there exists a way to work with Hibernate by using an already existing database without generating manually all the entities.
I'd like to know if there exists this sort of reverse engineering way to proceed.
If not, I would like to know what is the best strategy to follow in order to work with an existing database (I'm working with MySQL).

Related

Do I need to create DB migration, if I have a designed DB in MySQL?

I designed a database in MYSQL. Now I want to connect that with my Laravel application. But after researching, I understand that I need to migrate the database into Laravel by creating migration tables. But doing the same thing that I did in MySQL is tedious. I think there is another way to do the stuff. After searching I got this article from stackoverflow, but this is related to yii framework. I think someone knows here the solution of my problem.
I don't see a problem here, you can just connect Laravel to your DB (by editing your .env file) without any problems, migration files are just an easier way to design and implement your tables (also altering your tables' scheme on production is a very useful usage for migrations), but with that being done then no further actions are required, and you are good to go!
it's pretty obvious, you can update the database setting in the .env file and use DB::table('your_table_name') and get whatever query you want.
The upside of using migrations is that the exact same database can be created on different systems (ex: co-workers or acceptance/production servers).
Laravel migrations have an up and a down function so you can rollback to a specific version if something went wrong, very usefull when publishing your code.
That being said, co-workers could also review the database changes and for example hint at using more indexes and foreign keys.
As the other comments said, it's not a requirement you use migrations but it has considerable advantages versus creating and updating the database manually.

Liquibase create schema for MySQL

Is there any way to create schema through liquibase script ?
After some research I've found out that we need to include a create schema in change log file.
I'm thinking on similar terms for question asked previously for postgres
Any pointers or help is welcomed.
Found an answer that was mentioned already on stackoverflow.
We can create a fresh database using this URL.
jdbc:mysql://localhost:3306/database_name?createDatabaseIfNotExist=true
createDatabaseIfNotExist this keyword create a fresh new database in your system. If the database does not exist. if exist, skip executing.
Your proposed solution to your own question is to separate stuff by database, while your original question was about how to separate stuff using schema. Those are not the same.
If you are using Liquibase in "embedded mode", meaning it is your application code which controls Liquibase execution, not some Maven cmd or Liquibase CLI, then you can have a look at Pre-Liquibase.
Pre-Liquibase attempts to solve the chicken-and-egg problem inherent to Liquibase: It cannot be used to setup its own "home" (Liquibase needs two tables of its own that has to live somewhere), nor can Liquibase ChangeSets be used to create databases or schemas.
This is the problem which Pre-Liquibase solves. It executes some SQL prior to Liquibase itself. For example, you can use it with MySQL to make sure the database exists without fiddling with URL. In such case your Pre-Liquibase SQL script file would look like this:
CREATE DATABASE IF NOT EXISTS my_database_name
You can use Pre-Liquibase if you are using Spring Boot or just Spring Framework without Spring Boot. However, feel free to steal the ideas if you have another tech stack.
(full disclosure: I'm the author of Pre-Libuibase)

Is it okay importing a database instead of making a migration in laravel?

I want to create an api rest with laravel, and I have already designed my database. However, laravel doesn't allow me to create composite keys. Therefore, my question is, what could happen if instead of using migrations in laravel, I just create my database with sql and then make the corresponding connection?
You are free to do anything. You can even overwrite laravel as you wish. You have full control over laravel app. You can do whatever you like. Migration is there to assist you on many ways to create, update your database. This is no difference to what you would do without using it. It will not effect your application. You can import sql, Build your own schema. do whatever you want.

Slick Database Migrations

I'm working on a project using Scala which uses Slick.io for handling database interactions. I have the database schema implemented via Slick using its DDL.
This all works fine when I was starting out but now that I am some way into the project, making changes to the database schema is becoming a pain. I have to drop all the tables, manage data, re-create the schema etc...
I've previously used the PHP framework Laravel which had a nice way of dealing with database migrations & making changes to databases. This was done via a set of classes that were controlled by a timestamp and the "most recent" migrations could be run to make any changes to a database schema.
Does Slick have any equivalent?
Thanks
No, slick itself does not have an equivalent, but you can use something like:
Flyway:
https://github.com/flyway/flyway
http://flywaydb.org/
As you have not given any additional info:
for the play-framework there is an own module, which can be found here: https://github.com/flyway/flyway-play

grails/gorm/mysql/hibernate

I have a simples question. I have been trying to learn Grails by my own, and i managed to do a simple application using Grails/Gorm.
1 ) Later, i decided to use Mysql instead of Gorm - i just needed to configure the 'DataSource' and download the driver.
2 )So if i want to use hibernate between both (Grails and MYSQL) like this:
http://www.grails.org/doc/latest/guide/15.%20Grails%20and%20Hibernate.html, i need to make an 'hibernate.cfg.xml' file, and specify my mysql database url, user, pw etc .. and i have to map each Class in Grails for MySql columns.
So what is the diference between 1) and 2) ? and what exactly hibernate does. Give examples if possible
PS. Please correct me if i said something wrong, im kinda new to this
I think you are a bit confused here.
GORM is not a database, it is a ORM that maps you Groovy classes to database tables. It uses Hibernate under the covers to achieve this (Hibernate is also an ORM).
The default database Grails uses is an in-memory HSQL DB. If you want to use MySQL instead of that, all you need to do is change the settings in conf/DataSource.groovy.
You don't need to create any Hibernate xml files. That part of the documentation you've linked to is to allow people with existing Hibernate domain models to easily re-use them.
Hope this helps clear things up.
cheers
Lee