question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REST Data Panache: JPA Entity with multiple associations not consistently updated

See original GitHub issue

Describe the bug

When an Entity has multiple JPA associations (i.e. ManyToOne, ManyToMany and OneToMany), a removal to the ManyToOne field is not persisted when doing a PUT call.

Expected behavior

Get all the fields updated.

Actual behavior

The ManyToOne field is not part of the update.

To Reproduce

The reproducer is available at multiple-associations/hibernate-orm-panache-quickstart (based on from hibernate-orm-panache-quickstart from development branch).

To reproduce execute the test $ ./mvnw test -Dtest=PersonEndpointTest

Reproducer

The reproducer application has the Person entity with the following associations:

  • M:1 with Country
  • M:N with Fruits
  • 1:M with Car

The bean is deliberately missing the accessor methods for managing changes to associations with Fruits and Cars.

The test() method, basically, posts a Person with a valid Country and then it sends a PUT with a null country but the country is not updated consistently due to a “wrong” update query:

Hibernate: 
    update
        Person 
    set
        birth=?,
        name=? 
    where
        id=?

Commenting one of @ManyToMany or @OneToMany associations (@Transient annotation ready to be decommented) makes the test to work thanks to the execution of the expected update query.

I’ve also provided a testDb() method that works directly with the DB and it’s not affected by the same issue.

Configuration

Screenshots

Environment (please complete the following information):

Output of uname -a or ver

Linux 5.10.16-200.fc33.x86_64 #1 SMP Sun Feb 14 03:02:32 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment 18.9 (build 11.0.10+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.10+9, mixed mode, sharing)

GraalVM version (if different from Java)

Quarkus version or git rev

999-SNAPSHOT (build 20210323.071124-626)

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Additional context

(Add any other context about the problem here.)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mrizzicommented, Mar 29, 2021

Thanks a lot guys for the answers, both helpful 👍

0reactions
geoandcommented, Oct 13, 2021

Thanks for looking into it @Sgitario.

I haven’t followed this, so I’ll let the others comment

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best Practices for Many-to-Many Associations with Hibernate ...
Many -to-Many associations are very popular with JPA and Hibernate. Follow these best practices to avoid common pitfalls and create efficient mappings.
Read more >
Quarkus Panache OneToMany relation is not persisted in ...
I had the same problem and solved it by setting parent objects to children. I had Job and JobArgs items to persist.
Read more >
Simplified Hibernate ORM with Panache - Quarkus
Hibernate ORM with Panache focuses on making your entities trivial and fun to ... It takes fragments of HQL (JP-QL) queries and contextualizes...
Read more >
Hibernate's @Version annotation to enable Optimistic Locking ...
An OptimisticLockException must be thrown to avoid possible data override when two users try to update the same entity at the same time....
Read more >
Synchronization Methods for Many-To-Many Associations
The many-to-many association is a common thing in data modeling. In JPA entities, it is implemented as collections that store associated ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found