fix the problem with h2?
I have DTO:
https://gist.github.com/invzbl3/18bcb8823aaae64a236de2d4636dbe0c
and Entity:
https://gist.github.com/invzbl3/ca9b734a15202d0bd3f39cc013dd6508
I'm trying to save entity after convertation from dto into h2 database using JPA by the principle:
repo.save(entity)
my application.properties file:
https://gist.github.com/invzbl3/4de704993b2bb5766e4871b7b7f16a21
The problem is: h2 database doesn't have any data in Data Source, but in console I see:
https://gist.github.com/invzbl3/84e953032f65e9d8cea26aa50816de07
P.S. I'm reloading database using Refresh via command Ctrl+F5 and still no data in db.
I don't quite understand why it happens if frameworks like Spring Boot can be configured to perform Database Initialisation
How do you know that the DB does not have data?
I check own database inside data source
problem solved, it was related to configuration file👍
It's not clear where exactly that save call happens. And when exactly you check database state. save(entity) may not necessarily right away result in db insert. Google for something like "hibernate session", "jpa entity states", " jpa entity manager". https://www.baeldung.com/spring-data-jpa-save-saveandflush
😁😁😁 right a few seconds before I posted my idea)))
I've checked database in Data Source using refresh after sending request in postman and see in console that hibernate insert data, as you can on the screen
but in-memory was bad idea for saving entity))
Yes, inserts were in the last link, which I obviously was too lazy to click)))
I thought that in-memory can show me data which hibernate insert, but it doesn't work until I changed to jdbc:h2:file mode
Not at all. Bad idea is to use one db for tests, and completely other for prod. I'm 100% sure you won't use h2 ever in any real product
Yeah, agree. It's test task, so everything is ok 👍😀
Also thanks for link👍
Обсуждают сегодня