Spring Boot and H2 in memory database | Java Techie

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024
  • This video Explain how to use H2 in memory database in spring boot application with example
    GitHub:
    github.com/Jav...
    Blogs:
    javagyanmantra...
    Facebook Group :
    / 919464521471923
    Like & Subscribe

ความคิดเห็น • 98

  • @dhanashreechavan9395
    @dhanashreechavan9395 3 ปีที่แล้ว +3

    Nice Explanation.. by following instruction I able to create REST CRUD spring boot application successfully. Thank you so much

  • @dovydasbalciunas5002
    @dovydasbalciunas5002 ปีที่แล้ว +11

    You didn't show us working with h2 database?

  • @aditigupta6870
    @aditigupta6870 6 หลายเดือนก่อน

    Hi sir, can you help me with h2 db connection? II am strucked at memdb not found and I literally tried everything on internet and stack overflow.

  • @sasikala_chowdary
    @sasikala_chowdary 3 ปีที่แล้ว +5

    Sir, i am getting empty list when i use get method. I follow the same steps as you told in the video. I used the post method to inject values then ,when i use get method i am getting all curly braces with out any data{ {} {} {} } like this. I tried with restarting the server but still having the same problem.could you please help me to solve this problem.

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว +2

      You need to configure Lombok in your IDE

    • @sasikala_chowdary
      @sasikala_chowdary 3 ปีที่แล้ว +1

      @@Javatechie how to do that?

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      What IDE you are using

    • @sasikala_chowdary
      @sasikala_chowdary 3 ปีที่แล้ว +1

      @@Javatechie thanks, now my problem resolved. I forgotted to add getters and setters..

    • @sasikala_chowdary
      @sasikala_chowdary 3 ปีที่แล้ว

      @@Javatechie i am using spring tool suite 4

  • @soumenbanerjee4389
    @soumenbanerjee4389 2 ปีที่แล้ว +1

    I have a question for you, why you have added spring dev tools in pom file ?

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว

      I added it to enable live auto reload changes

  • @aditigupta6870
    @aditigupta6870 6 หลายเดือนก่อน

    Hi sir, can you connect with me please, little ugent, I need to setup h2 in my spring boot project but its showing driver not existing, I troubleshooted in many ways.

  • @valorant563
    @valorant563 ปีที่แล้ว

    all ok, no error showing, but whenever I am running the project as SpringBoot app, it's showing 61 common frames omitted. Also not strong the data in Postman..
    Showing Error: connect ECONNREFUSED (port)

  • @vigneshbalamurugan6537
    @vigneshbalamurugan6537 ปีที่แล้ว +1

    Bro I follow the same procedure but entity and Data some more annotation they were import Jakarta . persistence will be imported my project. So I check my h2 database table is not created ... Why bro please guide me😢

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      You are using spring boot 3 , in spring boot 3 there is a pkg changes javax pkg renamed as Jakarta .
      For your issue it says table not created so just configure Lombok in your ide it will solve your issue

  • @makr4nd361
    @makr4nd361 4 ปีที่แล้ว +2

    Whenever I include H2 database dependency there is an error in pom.xml file regarding H2 dependency ,why is it so?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      What is the error?

  • @ramcharanPhirangi
    @ramcharanPhirangi ปีที่แล้ว

    All my code is same, dependencies are same. But when I created objects in postman, creation is successfull. But in getall employees url, it is giving empty objects. Please solve my issue

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Please configure Lombok in your ide

  • @nidhichugh1527
    @nidhichugh1527 3 ปีที่แล้ว +1

    @java-techie Hi, I have written everything same only, but while sending post request on postman, I m getting error 404

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      Please check the proper url

    • @nidhichugh1527
      @nidhichugh1527 3 ปีที่แล้ว

      @@Javatechie yes I m giving correct url only and the port number is also correct

    • @nidhichugh1527
      @nidhichugh1527 3 ปีที่แล้ว +1

      @@Javatechie i have inserted records using post request, I m getting details saved, but while executing get request, it is giving 500 internal server error

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      Can you please share your error message in javatechie4u@gmail.com

    • @nidhichugh1527
      @nidhichugh1527 3 ปีที่แล้ว

      @@Javatechie hi, actually I created the constructor in the employee entity class. When I removed that, it worked... So what was the issue with the constructor??

  • @electricindro2236
    @electricindro2236 3 ปีที่แล้ว +1

    Is it possible to save the data in a file in system storage so that when the application gets restarted the previously stored data doesn't get lost?

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      Yes we can

    • @electricindro2236
      @electricindro2236 3 ปีที่แล้ว +4

      @@Javatechie it would be very kind of you if you can show us a demo through a simple project like this one.

    • @vaibhavgaur8200
      @vaibhavgaur8200 3 ปีที่แล้ว

      @@Javatechie yaa bring this video where we would save h2 database

  • @deepthinker1710
    @deepthinker1710 ปีที่แล้ว +1

    how much ram memory are you using ,yours is so fast mine is very slow

  • @shridharsable5125
    @shridharsable5125 ปีที่แล้ว +1

    nice explanation thank you

  • @sportsvideos1883
    @sportsvideos1883 3 ปีที่แล้ว

    Hello I am getting error like un used variables in employee.java file so I am not getting the mapping statement when I run my project kindly help me

  • @GodOfDeathShiva
    @GodOfDeathShiva 2 ปีที่แล้ว +1

    Unable to Reach the Mapping Methods, Mapping Methods is not showing in Console. Kindly pls help.

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว

      Is this error you are getting ?

    • @suryadattapendota1271
      @suryadattapendota1271 2 ปีที่แล้ว

      @@Javatechie no , you got mapped in console as shown in video but i didnt got.

    • @suryadattapendota1271
      @suryadattapendota1271 2 ปีที่แล้ว +1

      @@Javatechie bro, i followed the video as it is shown but im not getting data in postman console just getting {}{}{}..please help me to solve this

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว +1

      Did you configure Lombok in your ide if not please configure it or just manually add getter and setter method in your pojo

    • @suryadattapendota1271
      @suryadattapendota1271 2 ปีที่แล้ว +1

      @@Javatechie yeah brother, added getter and setter and i got it thanks.

  • @vaibhavsrivastava4645
    @vaibhavsrivastava4645 2 ปีที่แล้ว +1

    Very useful content to start with.

  • @rakeshroshan9690
    @rakeshroshan9690 4 ปีที่แล้ว

    I checked in /h2-console, Employee table is not not auto generating. what i have to do to get table auto generate ?

    • @rakeshroshan9690
      @rakeshroshan9690 4 ปีที่แล้ว +1

      added below property in application.properties, then started, now working fine
      spring.datasource.url=jdbc:h2:mem:testdb
      spring.datasource.driverClassName=org.h2.Driver
      spring.datasource.username=sa
      spring.datasource.password=
      spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
      spring.jpa.generate-ddl=true
      spring.jpa.hibernate.ddl-auto=update

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +2

      Only url is enough to go

    • @shreem6447
      @shreem6447 2 ปีที่แล้ว +1

      @@Javatechie Please pin your comment at the top (just the URL worked for me :)...

  • @manicr9939
    @manicr9939 2 ปีที่แล้ว +1

    Good start

  • @vigneshtj145
    @vigneshtj145 3 ปีที่แล้ว +1

    good video..but im getting 403...also tried to check whether table has created or not h2-console itself not opening

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      Check wrongly you might added spring security starter dependency

  • @moizshaikh8127
    @moizshaikh8127 4 หลายเดือนก่อน

    getting below error
    Error creating bean with name 'employeeController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'employeeRepository' defined in com.myProject.myApp.dao.EmployeeRepository defined in @EnableJpaRepositories declared on MyAppApplication: Not a managed type: class com.myProject.myApp.model.Employee

  • @raogaru306
    @raogaru306 ปีที่แล้ว +1

    Fastest project ever seen😮

  • @gelvinreyes
    @gelvinreyes 3 ปีที่แล้ว +3

    Great video, I have an issue, the DB it's creating the repository records, but with null data:
    {
    "id": 1,
    "name": null,
    "dept": null,
    "salary": 0.0
    },
    I'm using intellyJ, spring 2.5.0
    I did what's described in video step by step, could you please give an advise?

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว +3

      Please configure Lombok in your IDE . Go to plugins and add Lombok then re-start your IDE

    • @shiv5373
      @shiv5373 3 ปีที่แล้ว +2

      @@Javatechie It worked..Thanks a lot!!!

    • @hariharasudhans7828
      @hariharasudhans7828 ปีที่แล้ว

      help me i have a issue I can't import javax. Presistance. Entity instead of Jakarta Persistence

  • @vigneshbalamurugan6537
    @vigneshbalamurugan6537 ปีที่แล้ว +1

    Request method 'GET' is not supported error how to solve

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Please check the http method type that you have mentioned in the controller and what you are hitting from Post man . Both must be the same

    • @vigneshbalamurugan6537
      @vigneshbalamurugan6537 ปีที่แล้ว +1

      @@Javatechie now it will fine. I have another Problem it will store only null values in the h2 database table and how to solve this problem

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Please configure Lombok in your ide

    • @vigneshbalamurugan6537
      @vigneshbalamurugan6537 ปีที่แล้ว +1

      @@Javatechie yes bro I configured. Now everything is fine bro thank you

  • @menoktaokan
    @menoktaokan 4 ปีที่แล้ว +2

    guys don't forget to create getters and setters

  • @sarojsahoo8763
    @sarojsahoo8763 5 ปีที่แล้ว +1

    Dude here also I have the same question how do u make sure data is getting stored in H2 and data is getting fetched from H2

    • @Javatechie
      @Javatechie  5 ปีที่แล้ว

      Saroj please check in pom which dependency we added

  • @smitasawant9715
    @smitasawant9715 4 ปีที่แล้ว +1

    Data is inserting.. but while get method it's showing nothing but it's not giving error it just showing [{}]

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      Did you configure Lombok in your IDE , if not please do that and adding dependency is not enough to play with Lombok

    • @dp-sg8hc
      @dp-sg8hc 3 ปีที่แล้ว +1

      @@Javatechie thanks for your answer. i watched entire video and do changes but i got empty [{}] output for get operation. it is due to not configuring Lombok in my ide

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว +1

      Yes , do one thing if you are beginner manually add getter and setter method in entity and try

  • @nitesh85a
    @nitesh85a 6 หลายเดือนก่อน +1

    Which IDE? Pls share link with version

    • @Javatechie
      @Javatechie  6 หลายเดือนก่อน

      Intellij idea 💡

  • @ujjawalgupta5408
    @ujjawalgupta5408 3 ปีที่แล้ว +1

    Cannot find method - repository.findByDept(dept)

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว +1

      Create this method in your repository classes

    • @ujjawalgupta5408
      @ujjawalgupta5408 3 ปีที่แล้ว +1

      @@Javatechie Thanks isssue fixed

  • @namratajain7352
    @namratajain7352 4 ปีที่แล้ว +2

    Vedio is good I am not able to see H2 database

  • @avinashkunapareddy7429
    @avinashkunapareddy7429 4 ปีที่แล้ว

    How the data is storing without configuring data source in props or yml file

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +2

      Good question , this is an in memory DB so it's not mandatory to configure datasource for this .as you added h2 dependency spring boot is smart enough to create default datasource .

  • @पापानटोले
    @पापानटोले 4 ปีที่แล้ว +1

    i can't see the table in the database.
    Please help

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Do you add setter and getter ?

    • @पापानटोले
      @पापानटोले 4 ปีที่แล้ว +1

      @@Javatechie
      yes. already.

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Share me your request and dto class
      javatechie4u@gmail.com

  • @RubyReacts786
    @RubyReacts786 4 หลายเดือนก่อน

    Okay 😊

  • @PravinPatil02
    @PravinPatil02 3 ปีที่แล้ว +1

    How to write one to one relationship mapping in jpa spring boot

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว +1

      I already covered one to many please check that and do change for one to one

    • @PravinPatil02
      @PravinPatil02 3 ปีที่แล้ว +2

      @@Javatechie Thanks u quick response..😀😀 .. appreciate it

  • @dharmeshnamdev5866
    @dharmeshnamdev5866 4 ปีที่แล้ว +1

    where is H2 database saving the objects

  • @poojakhandhadia2324
    @poojakhandhadia2324 3 ปีที่แล้ว +1

    Can someone please help me how to check the h2 database?

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว +1

      Just type localhost:port/h2-console

  • @raj-mj3xn
    @raj-mj3xn ปีที่แล้ว

    Thanks helpful

  • @srikanththumati
    @srikanththumati 5 หลายเดือนก่อน

    i am getting error
    024-04-25 21:22:30.215 ERROR 20672 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
    java.lang.IllegalStateException: Cannot load configuration class: com.javatechie.h2.api.SpringBootH2Application
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at com.javatechie.h2.api.SpringBootH2Application.main(SpringBootH2Application.java:10) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    Caused by: java.lang.ExceptionInInitializerError: null
    at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 17 common frames omitted
    Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @3d680b5a
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
    at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:73) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 20 common frames omitted
    Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @3d680b5a
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) ~[na:na]
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) ~[na:na]
    at org.springframework.cglib.core.ReflectUtils$1.run(ReflectUtils.java:61) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) ~[na:na]
    at org.springframework.cglib.core.ReflectUtils.(ReflectUtils.java:52) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:243) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 32 common frames omitted

  • @gopald7263
    @gopald7263 6 ปีที่แล้ว +1

    Awesome...

  • @Ravikumar-gj6qw
    @Ravikumar-gj6qw 2 ปีที่แล้ว +1

    where is h2 console showned

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว

      In browser just hit localhost:port/h2-console

  • @neha6000
    @neha6000 6 ปีที่แล้ว +1

    great video