Coder Social home page Coder Social logo

Comments (9)

quarkus-bot avatar quarkus-bot commented on July 18, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

from quarkus.

yrodiere avatar yrodiere commented on July 18, 2024

Hey @alomine, thanks for reporting.
Are you sure this is specific to Quarkus? Can you reproduce with plain Hibernate ORM test case templates?

from quarkus.

alomine avatar alomine commented on July 18, 2024

Hello @yrodiere, thanks for response.
I'll try this. For now i can say two things - its not working in both quarkus 2.x.x version and 3.x.x (different hibernate versions) and its totally working on wildfly 26

from quarkus.

yrodiere avatar yrodiere commented on July 18, 2024

Thanks, looking forward to the reproducer.

from quarkus.

alomine avatar alomine commented on July 18, 2024

@yrodiere
I did two test cases with plain hibernate based on examples that you posted. Both 7/7 successful

from quarkus.

gsmet avatar gsmet commented on July 18, 2024

My guess is that it's related to the bytecode enhancement.

from quarkus.

Nikita-V0lkov avatar Nikita-V0lkov commented on July 18, 2024

I have some research on this issue.

1. Transactional annotation on the TestBugTest class instead of TestEntityService.

All tests will be passed, but the data in the database will not be updated.


2. QuarkusTransaction instead of annotation. You will have two possible variants:

2.1 Test fail, data not updated.

@Test
public void saveAndCheckWithNonNullNumber_test() {
    QuarkusTransaction.begin();
    testEntityService.clean();
    TestEntity testEntity = createEntityWithNonNullNumber();
    testEntityService.save(testEntity);
    QuarkusTransaction.commit();
    assertEquals(1, testEntityService.find(1L).getNumberField());
    
    QuarkusTransaction.begin();
    testEntity = createEntityWithAllNulls();
    testEntityService.update(testEntity);
    QuarkusTransaction.commit();
    assertEquals(null, testEntityService.find(1L).getNumberField());
}

2.2 Test passed, data not updated (similar to placing the Transactional annotation on the TestBugTest class).

@Test
public void saveAndCheckWithNonNullNumber_test() {
    QuarkusTransaction.begin();
    testEntityService.clean();
    TestEntity testEntity = createEntityWithNonNullNumber();
    testEntityService.save(testEntity);
    assertEquals(1, testEntityService.find(1L).getNumberField());
    QuarkusTransaction.commit();
    
    QuarkusTransaction.begin();
    testEntity = createEntityWithAllNulls();
    testEntityService.update(testEntity);
    assertEquals(null, testEntityService.find(1L).getNumberField());
    QuarkusTransaction.commit();
}

3. Update "refreshed" data after save (Transactional on TestEntityService).

3.1 Works as intended data in db updated.

@Test
public void saveAndCheckWithNonNullNumber_test() {
    testEntityService.clean();
    TestEntity testEntity = createEntityWithNonNullNumber();
    TestEntity savedEntity = testEntityService.save(testEntity);
    assertEquals(1, testEntityService.find(1L).getNumberField());
    
    savedEntity.setDateField(null);
    savedEntity.setNumberField(null);
    savedEntity.setStringField(null);
    testEntityService.update(savedEntity);
    assertEquals(null, testEntityService.find(1L).getNumberField());
}
public TestEntity save(TestEntity entity) {
    testEntityRepository.getEntityManager().persist(entity);
    testEntityRepository.getEntityManager().flush();
    testEntityRepository.getEntityManager().refresh(entity);
    return entity;
}

3.2 Save and find. Works similar to 3.1

@Test
public void saveAndCheckWithNonNullNumber_test() {
    testEntityService.clean();
    TestEntity testEntity = createEntityWithNonNullNumber();
    testEntityService.save(testEntity);
    assertEquals(1, testEntityService.find(1L).getNumberField());
    
    TestEntity savedEntity = testEntityService.find(1L);
    savedEntity.setDateField(null);
    savedEntity.setNumberField(null);
    savedEntity.setStringField(null);
    testEntityService.update(savedEntity);
    assertEquals(null, testEntityService.find(1L).getNumberField());
}

I hope this helps in some way.

from quarkus.

alomine avatar alomine commented on July 18, 2024

Hello @Nikita-V0lkov,
in 3.1 and 3.2 entity you named as savedEntity is in persistent state and in this state this seems to be working. However by explicitly calling merge it shouldnt really matter.

from quarkus.

marko-bekhta avatar marko-bekhta commented on July 18, 2024

Hey,

I did two test cases with plain hibernate based on examples that you posted. Both 7/7 successful

As Guillaume suggested, you'd need to add bytecode enhancement to reproduce the issue with Hibernate ORM only. Here's a bug report based on this in ORM's JIRA: https://hibernate.atlassian.net/browse/HHH-17761

from quarkus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.