Spring Boot Application doesn't write data to MySQL - mysql

I create a simple Spring Boot application. Running the app shows a JSON employee table in the browser, but when I check MySQL database with the command-line or MySQL Work-bench, a table employee table is generated, but no content.
Running the app from IntelliJ doesn't give me any error:
Take a look at my code on github:
demo

You have only static data you are not using Jpa method for save that's why it's not saving in database table.

Related

How to integrate Own Database in WSO2

I have installed WSO2 IS 6.0.0 and it is working. I have even configured Service Providers which are working fine.
Now I have my own MYSQL Database which has its own table(local_users) with users in it. There are around 10 users.
I want those users to be able to log in to WSO2 MYAcount using a username and password from the "local_users" Table and not WSO2 User Store.
I have read the documentation here which seems to only create WSO2 tables in MYSQL Database. But it doesn't take my table(local_users) from the same Database. I didn't find any option to give my table name or column name.
So my question is, is it possible to incorporate your own MYSQL DB Table with WSO2 Identity Server?
You can plug your own database which has user data as a userstore to WSO2 IS.
For that, you have to write a custom userstore manager to manage the user store, because the DB schema is different than the schema used in WSO2 default userstores.
Refer to https://nishothan-17.medium.com/custom-user-store-manager-for-wso2-identity-server-5-11-0-6e23a4ddf1bb this guide for more information on writing a custom userstore manager and plug your own userstore to WSO2 IS.

Do I need mysql dependency in Spring Initializr if I gonna use mysql in separate docker container?

I gonna create
Spring Boot MVC / JPA / Data CRUD project - simple REST service. Put in container
Store some data in mysql DB. Put in a separate container
use docker compose to up 1 & 2 together
Use a circuit breaker pattern (Hystrix?): #Retry & fallback methods while store to DB
Gonna use Spring Initializr
For that purpose I need to use:
Spring Web
Spring Data JPA
Options in Spring Initializr.
The question is: do a I need to use MySQL Driver: MySQL JDBC and R2DBC driver. option? Or mysql in separate container will be ok?
As this was explained in a comment, this entry has "Driver" in its name to indicate that this component is the "client part" to make sure your app can communicate with a MySQL server (be it in a separate container, a local instance on your machine or wherever).
start.spring.io is not providing services in any form. When it embeds something in the app itself, the entry has "Embedded" in its name to indicate that.

Spring Boot Jdbc Flyway Version File Name "V1__script.sql" not working instead renaming file with "V1_file.sql" is working

I have tried flyway(5.2.3) with Spring boot(2.1.0-Release) for MySQL (5.7) without JPA,
When I tried to run the Spring boot project the flyway version script file with the name "V1__script.sql" is only creating one table and it throws exception SQL Syntax error for the second table with local MySQL version.
If I have created the multiple files with V1__script.sql, V2__script.sql, V3__script.sql by having a single table script in it that is also working fine.
Version details :
Flyway: 5.2.3
Spring Boot: 2.1.0-Release
MySQL: 5.7
But when I renamed the file from "V1__file.sql" that works fine without any error.
Is there anything that I missed in the configuration. Is Flyway is not supporting "script" word in script file name?
Thank you.
Multiple statements are allowed in the sql script used by FlyWay. However it should be correct sql statements. Make sure you finished the lines with an semicolon(;)
The best test for a correct file is running it with something else. If you can import the file using mysql options table < V1__file.sql then FlyWay should work also.
If you rename the file to V1_file.sql it will be ignored by FlyWay.

EF Code First Mysql to SQL Server

I have an MVC 5 application that I first configured to use Mysql but now would like it to use SQL Server.
My app uses code first and migrations in order to generate the database.
After I changed all the required configuration I tried to run a Update-Database from the Package management console but I keep getting this error:
System.Data.Entity.Core.MetadataException: Schema specified is not
valid. Errors: (0,0) : error 0152: No Entity Framework provider found
for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'.
Make sure the provider is registered in the 'entityFramework' section
of the application config file. See
http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
This error appears after the database is created. It also appears when I run the application since it checks at that moment if there is any migration to do.
Somehow it still tries to use MySQL even though all providers point to SQL Server.
Any help would be more than welcome.
Thanks in advance
You need to follow the below mentioned steps to overcome above issue.
Step 1 : Use NuGet package to remove and install the relevant packages.This is very important.
If it's not working after the above step then you have to follow the below mentioned steps.
Step 1 : Get a backup of your project and SQL db and keep it in a safe place.
Step 2 : After that you have to delete all your data migration scripts on your app.
Step 3 : Delete the SQL db also.
Step 4 : Recreate all your Migration scripts again and after that run those against the SQL server.
Note : You need to do above steps b'cos it seems EF keep the provider details on the db migration scripts.

Generating Schema Queries for setting up mysql DB locally for Spring MVC project

I am learning Spring MVC. I have a project which I want to set up in my system for making some enhancements in the project. Its a Spring JPA Hibernate Maven based Project. The issue is I dont have schema generation queries for this project.
Can anyone tell me how can I generate schema creation queries from the hbm file of hibernate for setting up the db for this project.
Note:My database is Mysql 5.0
Thanks
You can try this code to which will generate .sql file which contains DB creation queries or you can set "hbm2ddl.auto" at create mode which will generate all the tables
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
SchemaExport se = new SchemaExport(cfg);
se.setDelimiter("\n#-----------------------------------------------------------------------------------");
se.setOutputFile("E:\\BackUP\\DB.sql");
se.create(true, true);// create(boolean script, boolean export)
Got the answer. We can do this using maven plugin- hibernate3-maven-plugin. Here is the link with complete details:
http://www.celinio.net/techblog/?p=1125