Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to see database changes in tests #40174

Open
rafasf opened this issue Apr 21, 2024 · 4 comments
Open

Unable to see database changes in tests #40174

rafasf opened this issue Apr 21, 2024 · 4 comments
Labels

Comments

@rafasf
Copy link

rafasf commented Apr 21, 2024

Describe the bug

Querying for a record after making a change using the #update, from PanacheRepository<T> method doesn't reflect the change.

Here's an example (the same as in the reproducer artefact attached):

1 Test

@Test
@TestTransaction
void changes_fruit_name() throws Exception {
   repository.persist(new Fruit("apple", "description", "a1"));
   repository.changeName("Apple: Gala", "a1");

    var fruit = repository.find("reference", "a1").firstResult();

    assertThat(fruit.getName()).isEqualTo("Apple: Gala");
}

2 The implementation of #changeName

@Transactional
public void changeName(String name, String reference) {
    update(
            "name = :name where reference = :reference",
            Parameters
                    .with("name", name)
                    .and("reference", reference));

}

3 Seeing the correct output

The interesting, or weird part is, the expected result is correct when using the entity manager directly, as shown below:

@Test
@TestTransaction
void changes_fruit_name_checking_natively() throws Exception {
   repository.persist(new Fruit("apple", "description", "a1"));
   repository.changeName("Apple: Gala", "a1");

    var fruit = (Object[]) repository.getEntityManager()
            .createNativeQuery("select * from Fruit where reference = ?")
            .setParameter(1, "a1")
            .getSingleResult();

    assertThat(fruit[1]).isEqualTo("Apple: Gala");
}

Expected behavior

Expect to see the record changed when retrieving with #find or other framework methods.

Actual behavior

The record returned has the information from the first time it was persisted, as part of the setup.

How to Reproduce?

reproducer-repository-test.tgz

Output of uname -a or ver

Darwin NDg2Nwo 23.3.0 Darwin Kernel Version 23.3.0: Thu Jan 4 13:56:14 PST 2024; root:xnu-10002.81.5~13/RELEASE_ARM64_T8112 arm64 arm Darwin

Output of java -version

openjdk 21.0.2 2024-01-16 LTS OpenJDK Runtime Environment Zulu21.32+17-CA (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Zulu21.32+17-CA (build 21.0.2+13-LTS, mixed mode, sharing)

Quarkus version or git rev

3.9.3

Build tool (ie. output of mvnw --version or gradlew --version)

openjdk 21.0.2 2024-01-16 LTS OpenJDK Runtime Environment Zulu21.32+17-CA (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Zulu21.32+17-CA (build 21.0.2+13-LTS, mixed mode, sharing)

Additional information

No response

@rafasf rafasf added the kind/bug Something isn't working label Apr 21, 2024
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 22, 2024

/cc @DavideD (hibernate-reactive), @gavinking (hibernate-reactive), @gsmet (hibernate-orm), @mswatosh (db2), @yrodiere (hibernate-orm)

@DavideD
Copy link
Contributor

DavideD commented Apr 22, 2024

I will have a look at the reproducer

@rafasf
Copy link
Author

rafasf commented May 5, 2024

I will have a look at the reproducer

Did you have a chance to take an initial look?

@yrodiere
Copy link
Member

yrodiere commented May 6, 2024

@DavideD is currently unavailable for a few weeks, but I'm sure he'll provide an update when he's back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants