Java Spring Boot - JPA - Hibernate - H2 - Database Initialization using data.sql and schema.sql

Поділитися
Вставка
  • Опубліковано 6 гру 2024
  • In this video we will learn how to initialize database using Java Spring Boot mechanism. We will use schema.sql file for DDL scripts and also data.sql for DML scripts. Using those files we will create database table and insert initial data. Later on we will also learn how to configure custom paths for those files, so they will be visible on classpath. Later on we will also create example entity together with CRUD repository to check out if we will be able to persist our objects into the database. We will use H2 Database and we will track everything web console. Everything exaplained step by step. Enjoy coding!
    Subscribe now for more videos: / @codeforgeyt
    Follow //CodefForgeYT on:
    FB: / codeforgeyt
    Twitter: / codeforgeyt
    GitHub: github.com/cod...
    Instagram: / codeforgeyt

КОМЕНТАРІ • 23

  • @ravinders9221
    @ravinders9221 3 роки тому +1

    hey thanks man, i did multiple projects with h2 integration after 6 months gap I forgot what I have done, wasted 2 hrs issue with inserting data. thanks man you saved my life.

    • @CodeForgeYT
      @CodeForgeYT  3 роки тому

      I am glad that video helped you! Keep Coding!

  • @carsmercholdjdm680
    @carsmercholdjdm680 4 роки тому +1

    Thank you! Very helpful! My only regret is I have not found your channel sooner

  • @gazizmalibekov2234
    @gazizmalibekov2234 4 роки тому +1

    thanks for video! helped me with property "spring.datasource.data" to validate data.sql

    • @CodeForgeYT
      @CodeForgeYT  4 роки тому

      Great to hear that! You are welcome!

  • @arshiakaul7863
    @arshiakaul7863 3 роки тому +3

    Thanks a lot, man! It was really helpful.

  • @arturorodriguez3110
    @arturorodriguez3110 2 роки тому +1

    very good video! mega helpful

  • @adityag974
    @adityag974 6 місяців тому

    If we have 2 schema how can we set the schema and data?

  • @xThexMasterxProx
    @xThexMasterxProx 2 роки тому

    can you import from a CSV using data.sql ? If so, how do I indicate the CSV path?
    Will this work?
    COPY table_schema.table FROM '~/src/main/resources/database/csv/table.csv' WITH (FORMAT csv);

  • @sujithg5873
    @sujithg5873 3 роки тому +1

    Bro one doubt no need to set spring.datasource.initializationmode?

    • @CodeForgeYT
      @CodeForgeYT  3 роки тому +1

      Depends, by default it is set to embedded.

    • @sujithg5873
      @sujithg5873 3 роки тому +1

      @@CodeForgeYT Thanks

  • @jonathandipita8994
    @jonathandipita8994 3 роки тому +1

    i followed all the steps but my schema.sql file still not executed. could you help me please
    ?

    • @CodeForgeYT
      @CodeForgeYT  3 роки тому

      Hi! Check if it is in correct location, otherwise spring will be not able to find it.

    • @cscs2539
      @cscs2539 3 роки тому

      @@CodeForgeYT I am facing same issue and file is at right location.

    • @cscs2539
      @cscs2539 3 роки тому

      I am facing same issue and file is at right location.

    • @cscs2539
      @cscs2539 3 роки тому +1

      resolved it , jdbc url was wrong so had to remove DB_CLOSE_DELAY=-1 and it worked

    • @wantedlepota9960
      @wantedlepota9960 Рік тому +1

      update the classpath to spring.sql.init.schema-locations=classpath:db/schema.sql

  • @programacaoja9679
    @programacaoja9679 3 роки тому +1

    what is the difference between data.sql and import.sql?

    • @CodeForgeYT
      @CodeForgeYT  3 роки тому +2

      Hey! data.sql can be used for inserting data to your database, schema must be already created. In case when you don't want to use default schema creation mechanism, you can create your own schema using schema.sql. Import.sql is specific for hibernate implementation and allows to load sql scripts. First two are spring specific and the last one is hibernate specific.