Skip to content
Advertisement

Will Converting my H2 memory database to a SQL database mess up any actual logic on my project? Spring Boot

I am currently using the H2 memory database for my website. Everything is working so far but to progress my teacher said to transition from the h2 database to a SQL since it resets everytime you restart the program. I was wondering if I transitioned, would it mess up any of my logic / code. I know I would have to make a database connector class, but I was just curious if I would have to edit the majority of the code so the information can be placed into the database.

Advertisement

Answer

It depends on what “kind” of “sql code” you have. If you are using Hibernate (e.g. through spring-data-jpa) and you only used annotations and never used @Query("some custom SQL code"), then you most likely are safe, as Hibernate knows how to translate java annotations to the respective database of your choice (h2, postgres, what have you).

However, if you have used custom queries, then those custom queries might start breaking, depending on the vendor you choose. E.g. if you have SELECT TOP 10 * FROM users that would probably work for Microsoft SQL Server, but could fail for Postgres.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement