Quarkus: Hibernate - @ManyToOne strange behavior

Created on 4 Oct 2019  Â·  33Comments  Â·  Source: quarkusio/quarkus

Describe the bug
Imagine the relationship described below:
"one" User -> "many" Message
In Message class, there is @ManyToOne(fetch = FetchType.LAZY, optional = false) User user; annotation.
When a new Message instance are created, we need to persist the object on database with related User "id".
I find the related User using EntityManager.find(clazz, id)

Expected behavior
Insert the new Message on database, do not make any operation with User

Actual behavior
After insert Message, Hibernate tries to update the User instance without any field.

To Reproduce
Steps to reproduce the behavior:

  1. Create a User instance on database and persist.
  2. In other transaction, create a Message and set the existent User
  3. Persist the Message

Configuration

# We are using Postgres Database

Can reproduce issue only in quarkus 0.23x, on 0.22 works fine with same config.

arehibernate-orm arepersistence kinbug

Most helpful comment

Hi @rafaelkloss , if you could share a little project reproduing it we will debug it.

Alternatively, could you try building a snapshot from Hibernate ORM master and try that?
We already fixed a related issue, so I'm wondering if it's the same (or not ..)

All 33 comments

cc @Sanne

@rafaelkloss could you create a simple project to reproduce it? It would be really helpful.

Hi Guillaume, i'll do asap

Best

Em sex, 4 de out de 2019 às 12:44, Guillaume Smet notifications@github.com
escreveu:

@rafaelkloss https://github.com/rafaelkloss could you create a simple
project to reproduce it? It would be really helpful.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/quarkusio/quarkus/issues/4377?email_source=notifications&email_token=ABUKGA2JRZULXKEXTEMCI7DQM5QFDA5CNFSM4I5PW7TKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAMCGBY#issuecomment-538452743,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABUKGA3IYRQ3BYSVIPFH2B3QM5QFDANCNFSM4I5PW7TA
.

--

{ name : "Rafael Kloss",

location : "Curitiba, PR",

iata : "CWB",

twitter : ["@rafa_kloss https://twitter.com/rafa_kloss"}

i'm trying to reproduce the issue using "hibernate-orm-resteasy" project, but i cant :(
Any other suggestion ?

HI Guys, there are news about the issue:
For example, in this relationship:
Class 'Solicitacao' have a relationship below with 'Usuario'
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "idUsuarioSolicitacao") private Usuario usuarioSolicitacao;
Class 'Usuario' have relationship below with 'Cargo'
@ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "idCargo") private Cargo cargo;
Class 'Cargo' have a relationship below with 'Cliente'
@ManyToOne(optional = false) @JoinColumn(name = "idCliente") private Cliente cliente;
When we try to persist a new Solicitacao (first class above), see the difference between 0.22.0 and 0.23.2 qurkus versions:
Screen Shot 2019-10-09 at 2 50 05 PM
Screen Shot 2019-10-09 at 2 53 53 PM
In the 0.22.0, threre is the 'Cliente' instance, but in 0.23.2 the 'Cliente' instance is null and hibernate tries to update 'Cargo' instance with a null 'Cliente' instance causing SQL constraint exception.

Hi @rafaelkloss , if you could share a little project reproduing it we will debug it.

Alternatively, could you try building a snapshot from Hibernate ORM master and try that?
We already fixed a related issue, so I'm wondering if it's the same (or not ..)

Hi @Sanne, what is the related issue ?

@rafaelkloss any progress on the reproducer? We really need it to be able to fix that one. And it really looks like a nasty bug so the sooner the better!

Thanks!

BTW, the issue Sanne was talking about is this one: https://hibernate.atlassian.net/browse/HHH-13653 . It has been fixed in the current master of Hibernate ORM but we do not know if it's the same bug or not.

Hi @rafaelkloss,
I have created a branch https://github.com/dreab8/qurkus-merge-detached/tree/issue-4377 on my repo with a test ManyToOneTest#testRequestHasAnAssociatedClient() trying to reproduce the issue you described but without any success, can you please tell me if I missed anything?

Thanks

Hi guys, sorry for delay, i'm out of office until tomorrow. I'll try to
reproduce this asap.

Em qua, 16 de out de 2019 às 07:35, Andrea Boriero notifications@github.com
escreveu:

Hi @rafaelkloss https://github.com/rafaelkloss,
I have created a branch
https://github.com/dreab8/qurkus-merge-detached/tree/issue-4377 on my
repo with a test ManyToOneTest#testRequestHasAnAssociatedClient() trying
to reproduce the issue you described but without any success, can you
please tell me if I missed anything?

Thanks

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/quarkusio/quarkus/issues/4377?email_source=notifications&email_token=ABUKGAYHZRRYZ7JZH5CSCJTQO3VAZA5CNFSM4I5PW7TKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBMAGKY#issuecomment-542638891,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABUKGA7IFHBTTLMRQ7VRBU3QO3VAZANCNFSM4I5PW7TA
.

--

{ name : "Rafael Kloss",

location : "Curitiba, PR",

iata : "CWB",

twitter : ["@rafa_kloss https://twitter.com/rafa_kloss"}

HI guys, i updated to Quarkus 0.25.0, but now there are other issue before described above.
[org.hib.pro.poj.byt.ByteBuddyInterceptor] (executor-thread-1) HHH000179: Narrowing proxy when i find the Company of User.
I suspect there are any problem with my (generic) .equals or hashcode methods in my "abstract model" persistent class.
Any other way for me to go and find out the root cause of the issue?

@dreab8 about your class model, there is a 'AbstractModel' with generic equals and hashCode methods like below:
`public abstract Integer getId();

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    AbstractModel abs = (AbstractModel) o;
    if (null == getId() || null == abs.getId()) {
        return false;
    }
    return Objects.equals(getId(), abs.getId());
}

@Override
public int hashCode() {
    return Objects.hash(getId());
}`

Do you think the two problems are linked to each other?
For reproduce the main error in this issue, i need to back to Quarkus 0.23.2

Hi @rafaelkloss can you please modify my project in order to reproduce the last issue you described? Thanks

Hi @dreab8 i'm trying to do this right now

Hi @dreab8 i have good news, take a look on this repository https://github.com/rafaelkloss/quarkus-many-to-one-error
I "destructed" my own project and keep the architecture for reproduce.

When you debug, make a breakpoint on ErrorHereServiceImpl line 30

I did a fast class diagram to demonstrate my model
Screen Shot 2019-10-25 at 10 34 27 AM

@rafaelkloss thanks a lot for the reproducer, I'll look at it.

A note from @dreab8 : this issue (also) seems related with self-dirty-tracking being enabled during build time enhancement.

Hi guys, thanks for the effort, so far we are using 0.22.0.

There are any workaround for this ?

a valid workaround seems to be to disable auto dirty tracking, but Quarkus currently enforces it. (That was my choice, as having too many such options makes it hard for us to maintain all possiblities)

Patching Quarkus to allow to disable this is simple enough but it's not a good idea as it would require different code being generated by Panache.

Feel free to experiment with this pr?

The proper solution likely belongs in an ORM (I think, I haven't spoken with @dreab8 yet) but this will need a bit more time.

Hi Sanne, thanks for reply, i wait for the finish of issue.
@dreab8 you did it reproduce using my project example ?

Hi guys, even i don't understand why works fine until quarkus 0.22.0, before 0.23 the "auto dirty tracking" is disabled ?

Hi guys, any update on this ?

Hi guys, i'm really preoccupied with this issue. What more i can do to solve this ?
Thanks for understanding

hey @rafaelkloss , I'm sorry for the delay - we had several complex issues to analyse and it's a small team :)

I've been tempted to disable dirty tracking by default, but it would have been only a temporary workaround - and it would have had consequences on other features - so decided to not do that, but rather we should get to the bottom of this.

We'll get back to this soon.

@rafaelkloss there's a PR for your issue here: https://github.com/hibernate/hibernate-orm/pull/3092

It's going to need careful reviewing though. @dreab8 added your use case among the integration tests, but if you'd like to have a look anyway feel free to experiment with it!

@rafaelkloss https://github.com/hibernate/hibernate-orm/pull/3092/files#diff-53443eae565c48423e6bacc6ea9f3b0e is based on you reproducer

Thanks :)

hi @rafaelkloss we merged the Hibernate ORM upgrade, this should be fixed now thanks to @dreab8 .

Since he ported your test to be incorporated into the ORM integration tests, I'm closing this one but please could you check on your original case as well :)

Hi folks, thanks for your effort, this is a great new !
Very best :)

Em sex., 15 de nov. de 2019 às 08:28, Sanne Grinovero <
[email protected]> escreveu:

hi @rafaelkloss https://github.com/rafaelkloss we merged the Hibernate
ORM upgrade, this should be fixed now thanks to @dreab8
https://github.com/dreab8 .

Since he ported your test to be incorporated into the ORM integration
tests, I'm closing this one but please could you check on your original
case as well :)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/quarkusio/quarkus/issues/4377?email_source=notifications&email_token=ABUKGA2PG3BSECIJ3MLANH3QT2BXPA5CNFSM4I5PW7TKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEFFIGI#issuecomment-554325017,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABUKGA6QZIWQGXT5XGQIISTQT2BXPANCNFSM4I5PW7TA
.

--

{ name : "Rafael Kloss",

location : "Curitiba, PR",

iata : "CWB",

twitter : ["@rafa_kloss https://twitter.com/rafa_kloss"}

Was this page helpful?
0 / 5 - 0 ratings