stop using H2 in memory-database RIGHT NOW

Поділитися
Вставка
  • Опубліковано 7 чер 2024
  • H2 is an in memory database which is misused quite a for testing. In this video I will to discuss the drawbacks of using H2 in memory database and what are the alternatives.
    60h Full Stack Professional Course - amigoscode.com/courses/full-s...
    Don't Forget to
    ===========================================
    💯 Subscribe to Amigoscode - bit.ly/2HpF5V8
    💯 Courses Available for free here - amigoscode.com/courses
    💯 Join Private Facebook Group and Discord - amigoscode.com/p/join-community
    🙊 Here are the goods for all my videos video 🙊
    ► Recommended Books
    ===========================================
    - Clean Code - amzn.to/2UGDPlX
    - HTTP: The Definitive Guide - amzn.to/2JDVi8s
    - Clean Architecture - amzn.to/2xOBNXW
    ► Computer and Monitor
    ===========================================
    - New Apple MacBook Pro - amzn.to/3464Mmn
    - Dell 27 INCH Ultrasharp U2719D Monitor - amzn.to/2xM3nW1
    - Double Arm Stand Desk Mount - amzn.to/3aYKKfs
    - USB C Hub Multiport Adapter - amzn.to/2Jz7NlL
    ► Camera Gear
    =============================================
    - Sony ILCE7M3B Full Frame Mirrorless Camera - amzn.to/346QIJn
    - Sigma 16 mm F1.4 DC DN - amzn.to/2wbic3Q
    - Sigma 33B965 30 mm F1.4 DC DC - amzn.to/39G37Fd
    ► IDE & Tools I use for coding 💻 🎒
    ===========================================
    - ITerm
    - VsCode
    - GoLand
    - IntelliJ Ultimate
    - Sublime
    P.S
    ===========================================
    💯 Don't forget to subscribe | bit.ly/2HpF5V8
    💯 Join Private Facebook Group and Discord - amigoscode.com/p/join-community
    💯 Follow me on Instagram | bit.ly/2TSkA9w
    ❤️ Thanks for watching
  • Наука та технологія

КОМЕНТАРІ • 97

  • @ChandlerBing11
    @ChandlerBing11 Рік тому +97

    Hey, Nelson, you could record a tutorial teaching How to configure this AbstractTestcontainers and all that stuff to replace H2 DB. That's really useful, your videos are amazing

  • @asjjain191183
    @asjjain191183 Рік тому +8

    Whatever you are talking about, maybe true for complex projects or high data loads. But 90% of projects have very simple crud operations. Anyhow, it's not always about unit testing. Before going to production, usually, code is tested by QA, performance, load testing, security team and UAT. with h2 database writing test cases is easy.

  • @kelvinbirikorang1877
    @kelvinbirikorang1877 Рік тому +7

    I still think H2 in testing is fine, if you ain't performing limited / any database-specific functions. Spinning up docker to run something simple during integration test, hmm it seems overkill

  • @sadeepaalwis5938
    @sadeepaalwis5938 Рік тому +12

    Loved the video Nelson please do a tutorial on TestContainers and setting it up a little in depth ❤ Thank you!

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

    really great Nelson! Thank you so much for sharing. I've been following you since the beginning and I can say your content helped me a lot on my career, I'm an amigoscode fan definitely haha. I really want to buy the Full Stack Professional course but right now my budget is a little tight, would be awesome to get a magic coupon code. Thank you so much for everything, you're an inspiration to me!

  • @sadiqshaikh8715
    @sadiqshaikh8715 Рік тому

    Hey amigo i just wanted to let you know I got into software development recently and you have been a great help keep up the good work man❤

  • @hotshotgolfer3079
    @hotshotgolfer3079 7 місяців тому +1

    Love the way you teach! I just finished my first h2 todo project. But I am from PHP and MySQL so I needed some instruction on host to get a MySQL database with the JAVA project instead of H2. This was a little over my head. I am off to your website to see if you have a course that might fit my level a little better. TY!

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

    I have also encountered situations where the testing results of H2 Database and PostgreSQL are different.
    This video has further convinced me that H2 should not be used.
    Thank you for sharing.

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

    Perfecto Amigo, we need the tutorials on test containers and all the testing stuff in spring boot soon. Love you ❤

  • @trustDproc3ss
    @trustDproc3ss Рік тому

    Thanks for this, this approach is good for developer using docker.

  • @aminesafi7261
    @aminesafi7261 Рік тому

    Great content, keep going bro!

  • @andreiisachenko6755
    @andreiisachenko6755 Рік тому +3

    Hello, Thank you for the video. I have 7+ years production expedience and want to add few moments which i learned). So better a bad test than no test). Yes h2 is not totally equal to production ready databases and what works on h2 might not work on MySql,Postgres... But it is

  • @hovasty
    @hovasty Рік тому +2

    Great video. Please show us how to do test containers :)

  • @andresnator
    @andresnator Рік тому

    Thanks for your videos

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

    Thank you. Would love to see the TestContainers video

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

    Thank for granting my wish, amigo! I know this video is just not for me but I am also one of the people who requested it. Even in your big time of fasting 🥰

  • @michelchaghoury9629
    @michelchaghoury9629 Рік тому +2

    We need more videos about testing and about Test Containers and Integration Testing.
    Please can you in the future make tutorials about Spring Boot Reactive?

  • @ainigma100
    @ainigma100 Рік тому

    Thank you for the great video!

  • @alaeddingarraoui4538
    @alaeddingarraoui4538 Рік тому

    THANKS Nilson, always wonderful video ! . I'd love to make a video on how to use docker to replace H2 cos right now I'm learning it, and still I'm not quite sure to understand how to use it in a concrete project like this your project.

  • @rafabanasiewicz3074
    @rafabanasiewicz3074 Рік тому

    Hey Nelson!
    Where can I find your code formatter setup?
    Also I’m staying with dillema which MacBook Pro is best For fullstack oriented programming with a budget of 2k$ (prefer 14’ ones)
    It will be better to buy M2 Pro or M1 Pro with upgraded RAM? Or maybe other one with Intel processor?

  • @georgepro8481
    @georgepro8481 Рік тому

    Hello, Nelson! Is it possible to launch testcontainers automatically before tests start? And stop it after?

  • @elhadjbabacarcisse2868
    @elhadjbabacarcisse2868 Рік тому

    Hello Nelson, thanks as usual. Can you make a video on TestContainers and your configuration? Thanks mate

  • @marianacagnoni3205
    @marianacagnoni3205 Рік тому

    we're all waiting for the testing containers tutorial sir
    thanks for the good content!

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

    Hi Yes we need this video about containers.

  • @kalden.s814
    @kalden.s814 Рік тому +2

    Yes please make a video on testing (for controller, repository and service layer).
    I don't understand how to test😢
    I can write code but i cannot write tests for it😑

  • @aleksandarivanov8824
    @aleksandarivanov8824 Рік тому

    Great video! I would like if you could put a video from scratch about test containers.

  • @safirahman1612
    @safirahman1612 Рік тому +3

    Hi Amigoscode! I'm starting my first Java developer job in the coming month and I'm really nervous. Can you please make a video with the test setup that you have?

  • @tarikmujcic2966
    @tarikmujcic2966 Рік тому

    It would be REALLY good to have the video on test containers

  • @axslv
    @axslv Рік тому +3

    While H2 is not recommended sometimes using it is the only way to have your tests. For example, the most recent client of ours provided us with their CITRIX vms, so this rendered both docker and testcontainers impossible to use. What I want to say is that we need H2 in order to cover ignorance of our clients. So again, when we have "theory" VS "real world" problem. Thanks for this video!

    • @RochaNahuel
      @RochaNahuel 11 місяців тому

      I am studying his course from two years ago on JUnit testing and he recommends using H2, in fact he is teaching it, at that moment the thumbnail of this video came to mind, now I don't know if I should learn like this or not...?

  • @patryktraczyk3246
    @patryktraczyk3246 11 місяців тому

    AbstractTestcontainers would be really great to see! Hope you can prepare such material soon 😀

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

    I would also like to watch a video about testcontainers, especially with spring boot 3.1

  • @danielkirsch4351
    @danielkirsch4351 Рік тому

    Awesome Nelson, testcontainers vid pleeeese!😊

  • @slota4
    @slota4 Рік тому

    yes, please make some example how to setup TestContainers, how to use it :) will be helpful for sure.

  • @zakharborisov1841
    @zakharborisov1841 Рік тому

    Should I mock repository in service layer? If I tested custom queries of repository using testcontainers?

  • @adrianilie28
    @adrianilie28 Рік тому

    Yes! Please! I'm interested in Testcontainers :)

  • @shayuru
    @shayuru Рік тому +2

    It sounds fine, but it works on the Development environment (local), but this cannot be easily done over automated CI/CD, e.g. Jenkins or GitHub Actions, it is possible but requires extra resources and configuration and create a dependency on the database (must be running before the test), UTs are supposed to be isolated. that's why mock libraries were created, I understand your point I've created UTs that run against a "real" database, but I've disabled them when running the automated CI/CD because I cannot modify the "DevOps infrastructure" just to run containers.

  • @zhandosyernazarov3086
    @zhandosyernazarov3086 Рік тому

    Hi, I would love to see a video on setting up TestContainers

  • @sirfinsaan
    @sirfinsaan 4 місяці тому

    what about external service ? should we mock or any other approach

  • @bryceblankinship
    @bryceblankinship Рік тому

    Ran into this at work recently. H2 dialect for Oracle isn’t complete and it was literally impossible to test my DAO and had to mock it… which is useless!

  • @0107007
    @0107007 Рік тому

    Hi! What do you think about using SQLite as an alternative to H2? I know it has similar limitations but if the application is small or simple it may works well, right?

    • @johndoedoejohn
      @johndoedoejohn Рік тому

      I guess mongoDb would be good option with mongo atlas, but it's nosql

  • @user-go7iy8gy2t
    @user-go7iy8gy2t Рік тому +2

    yes, we want to see how to use testcontainers from scratch, plz

  • @MarcioJustoDev
    @MarcioJustoDev Рік тому

    Please Nelson! A video for testcontainers, including with kafka reactive! hands 🙏🏾

  • @Muescha
    @Muescha Рік тому

    please do a deep dive tutorial into testcontainers

  • @pierrelaurensflorez2273
    @pierrelaurensflorez2273 Рік тому

    Hey Nelson! Good video. I would like to see a TestContainer tutorial on using it, and I have a quick question. If I'm using an interface that implements JPARepository without using custom queries, should I need to write unit test for the original operations? Should I test the interface? Or should I create a class that implements my custom interface and then create a unit test for this new class? I really appreciate this video Nelson!!

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

      Isn't necessary to test this JPA interfaces, You'll need to test it just in case of having custom queries. All "default" queries are tested over years by spring community :)

  • @ammanul543
    @ammanul543 Рік тому

    Hi i had one doubt can't we use mockito instead of actual database call?

  • @akashranjan930
    @akashranjan930 Рік тому

    Hey Nelson! can you make tutorial on SpringAOP, couldn't really find any perfect explanation

  • @NakMs
    @NakMs Рік тому

    For the container db test, it quite take time when run.

  • @zakariaeelbouayadi3222
    @zakariaeelbouayadi3222 Рік тому

    Assalamu alaykum and Thank you very much

  • @Muescha
    @Muescha Рік тому

    how you have automated the firework at the end of the tests?

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

    I mean, this is why we use abstraction. DBs might have differences, but we should develop app as flexible as possible. So using H2 is good if it’s justified. If we use some specific function from PostgreSQL in out test, maybe we should consider changing it

  • @simbarashemaunga5575
    @simbarashemaunga5575 Рік тому

    This may trigger someone but I say it in good faith. Consider setting a poll on whether or not you should continue with these new thumbnails where you look shocked/confused etc vs the legendary thumbs up.

  • @arturxavier1481
    @arturxavier1481 Рік тому

    But how would I setup the docker in a CI environment?

  • @gaetanbayenay8730
    @gaetanbayenay8730 Рік тому +11

    Hi,
    Just a quick comment... In general in Java world, you should use JPA and Hibernate (or similar) to handle DB. So, as far as you're using this abstraction, there is no big deal to use H2. And by the way, the use of custom DB functions is discouraged. Better to stay with "standard SQL" (or similar from Hibernate).
    So it means it's perfectly safe to use H2 to make some kind of unit tests, for instance those that ensure the correct lazy loading or the persistence effectiveness, your real (basic)persistence logic, etc... And it's not replacing integration tests with whatever DB you want...
    An advantage to H2, is the possibility to launch directly some SQL script in the connection String. That way, you can initialize a database correctly (with specific SQL like the one that was created by the DBA).
    True story, if I was not trying to use H2 on one of the project I collaborated, then I never been able to detect fundamental PROD DB problem. It was precisely because I forced myself to standardize things through JPA and Hibernate, and validated both local H2 and other environment Oracle that I found some previous migration was not completed correctly...
    I'll not advocate to use H2, I'll just wanted to say it's another great tool that can be used. It's a little unfair to say it's not safe, if you pay attention to the limitations...

    • @maksym.pavlenko
      @maksym.pavlenko Рік тому

      Correct me if I'm wrong, but in case if I cannot avoid using a feature provided by a custom DB function, I'd use it, rather than inventing a wheel by implementing it myself and putting a responsibility of supporting this logic on my team

    • @gaetanbayenay8730
      @gaetanbayenay8730 Рік тому

      @@maksym.pavlenko, I'll say that you can maybe challenge the real necessity to have the custom DB function. And well, if it's really not possible to do without this custom function, then there is no reason to not use it. It's just that you can "skip" the particular part that use the custom function by skipping the H2 test, and try to have unit tests / integration tests with H2 for everything else. Then it's a matter of isolation, more than avoiding custom DB functions.

    • @maksym.pavlenko
      @maksym.pavlenko Рік тому

      @@gaetanbayenay8730 all this comes from unreliability of such functions or the fact the migration to another DB without unsupported functions could be easier?

    • @gaetanbayenay8730
      @gaetanbayenay8730 Рік тому

      @@maksym.pavlenko I think it's more complex than that. If the goal is to have the ability to change DB, then the standardization is a must. So, higher expectation means to think about the problem (and the way the data are stored) differently. It's not only the pure data, or the way to handle them, but also the meaning of the data organization. That's the reason why it's important to challenge the real need for custom function.
      Another point is how to deal in code with the data. If a custom function can be avoided by using similar data manipulation within Java (for instance with java streams), or by rethinking the separation of concerns with a split into microservices, then it's also a valid answer to the problem.
      And maybe it's the DB technology itself that can be changed (by using non relational DB, or something totally different).
      So, there is room to avoid custom functions, depending on the needs and the liberty in adressing the problem... :) ... But at the end, if the functions exists, there is a need too, and good reasons to use them, with the knowledge that the code is no more standardized.

  • @RochaNahuel
    @RochaNahuel 11 місяців тому

    You should update your JUnit course from 2 years ago where you literally recommend using H2 , or add some notification in that video.

  • @azeemcr37
    @azeemcr37 Рік тому

    Need TestContainers video 🔥🔥🔥🔥

  • @radecki125
    @radecki125 Рік тому

    we want to see testcontainers!

  • @DevLearn-lv7nr
    @DevLearn-lv7nr 4 місяці тому

    H2 is absolutely fine for QUCK testing, without going to the effort of a "near to production as possible" environment

  • @darioanguilla3147
    @darioanguilla3147 Рік тому

    Testcontainers deeply from scratch please!

  • @FredrickIrubor
    @FredrickIrubor Рік тому

    Docker is a life saver

  • @Rostik_13
    @Rostik_13 Рік тому

    "How to configure this AbstractTestcontainers and all that stuff to replace H2 DB?"
    Just do it, please😎👊

  • @MrBgdu26
    @MrBgdu26 Рік тому

    That’s cool but when I try it on my PC, with an Oracle test container, it takes 2 minutes to run a single test

  • @marcosdantasguimaraesfilho7747

    Please do record a video on setting up TestContainers! That's soooo useful!!

  • @LifeOfMohammed
    @LifeOfMohammed Рік тому

    This is not ideal for tests though as with tests I run them on an environment that doesn't have a database instead just uses the memory database

  • @IndritVaka
    @IndritVaka 8 місяців тому

    The video was great, but why you have to add that rainbow??

  • @zombi1034
    @zombi1034 3 місяці тому

    Easy solution. Just use H2 in production😎

  • @trocandobytes
    @trocandobytes Рік тому

    What about SQLite ?

  • @daniel_goncalves
    @daniel_goncalves Рік тому

    Show how tô do this

  • @felipe1876
    @felipe1876 Рік тому

    Ok. I promise that. Can you hire me?

  • @maximilianh7728
    @maximilianh7728 Рік тому

    hey amigoo

  • @maulikdavra389
    @maulikdavra389 10 місяців тому +1

    Dear Nelson
    If you are opposing of using H-2 in first place then why haven't you updated your course "software testing" (listed on your website) which uses H-2 db. On top of that throughout the course you are mocking repository layer and injecting mock on service layer. If this is not the best practice to follow then why you haven't you updated this course with docker implementation. H-2 is quite good with basic CRUD operations but docker is one of the safe and reliable option for testing.
    Please record a video for unit as well integration testing with docker test containers. At least this would help me learn all the major concepts of software testing.
    But I am still not clear if mocking service layer or repository layer is OK for isolation testing or even unit as well as integration testing!
    what type of testing practices an enterprise company follows ?

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

    Why? h2 is excellent to teach the basic of SQL without messing with a db install. H2 is not designed for a production serious enviroment. Learn the basic of ORM, SQL, JDBC and then kick off the H2 if you want.

    • @fernandorivera4719
      @fernandorivera4719 Рік тому

      I have been trying for weeks to create the simplest application: something that creates users and saves it into an H2 database.
      But for some godforsaken reason, all POST requests made to the register endpoint return a status 200 instead of a 201, so nothing is ever created on the database.
      Why? I have asked everyone, from teachers and professionals, to chat GPT and no one seems to find the answer.
      I'm beginning to think the issue may be related somehow to the H2 database. I see no other explanation.

    • @antonpirulero2836
      @antonpirulero2836 Рік тому

      @@fernandorivera4719 ... its a conspiracy ...

  • @zhenka1982
    @zhenka1982 Рік тому

    I am a principal software engineer. I like a lot of your videos and give you props for explaining best practices to junior engineers in a clear and concise way. However, this video is an exception.
    Judging by the comments, nobody really understood your point. And I must say, your point is lost because for some reason you are talking about H2 and “in memory-database” like that’s something special.
    The only sensible thing you can say is that a test environment should as closely as possible mimic the production environment. Now that’s a true statement. What does H2 in particular have to do with the price of tea in china?
    Same would be true if you said “Don’t use Oracle to test MySQL queries”. Now, I get it, you are trying to say, that the ease of getting an H2 running makes it super easy to use for testing. But that’s largely irrelevant, for the point you are trying to make.

  • @togerait
    @togerait Рік тому

    The H2 technology is used by many book authors to explain concepts. I have never liked this foolish approach, and I am happy to see someone who thinks like me for the first time.

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

      is that means H2 has no use cases? can you explain why did you call it foolish approach?

  • @tepchiva8342
    @tepchiva8342 2 місяці тому

    Could you please publish source code?

  • @nandux586
    @nandux586 Рік тому

    Hey man. I appreciate your content, but the thumbnails are kind of off putting. 😬

  • @Abrahhhhh
    @Abrahhhhh Рік тому

    First🎉🎉🎉

  • @sadiqshaikh8715
    @sadiqshaikh8715 Рік тому

    Second🎉

  • @user-mg1mk5on3l
    @user-mg1mk5on3l Рік тому

    You can have his course for free. Dont buy his overpriced course

    • @NEMOBANDZBEATS
      @NEMOBANDZBEATS Рік тому +3

      If you get a lot of value from his content why not show some support ?

  • @haltsmaul.
    @haltsmaul. Рік тому

    I'm developing a small application that uses an H2 DB and got real spooked 😳.

  • @AndriiKovalov
    @AndriiKovalov Рік тому

    I agree that nowdays it is a best practice to use testcontainers to have best compatibility across all environments. But for those who stuck with H2 for any reason, keep in mind that you have some flexibility by creating aliases for Java based functions, ie: CREATE ALIAS IF NOT EXISTS TRUNC FOR "my.package.MyH2Functions.trunc";