I have a bit of a silly question that has been really stressing me out these past few days. We have a a test integration suite on one of our services that uses
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
for each test. We will have a local Postgres set up and we set the configuration in properties file. So we configure an entity manager and persist and flush set up data, we're able to do integration tests against the service and it all works great.
However whenever I debug one of these tests, I never see the data in my actual local database. I'll query the tables and they're all empty. I can see that in the entity manager it has a persistence context with all of the pre-set up data, but that doesn't make sense that we aren't really using the database? I know we are because if we change a column in the database the test will fail if the Entity hasn't been updated or vice-versa.
The reason why this is stressing me out is because I have written some code for a hibernate-search feature and in there I open a new session with the EntityManagerFactory
Session session = (this.fullTextEntityManager.unwrap(Session.class)).getSessionFactory().openSession();
Do the hibernate search query and when the service is running it works great. I have to create this new session because for some reason we had a single fullTextEntityManager bean that we were sharing across the service and it was pulling up old data whenever did a search due to it saving the search data in the persistence context, and in a multi-instance environment that just caused a lot of issues.
However now that I create this new session, our integration tests fail because it is unable to find the data due to it not pulling from our configured EntityManager for our test suite. I guess I'm just wondering with this @AutoConfigureTestDatabase , how come I can't find any data when I open a new session and where does the data go? Shouldn't it be flushing data to the database and why don't I ever see data in there?
Aucun commentaire:
Enregistrer un commentaire