Skip to content

Persist of entity mapped with a non nullable association causes UnsupportedOperationException #1077

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

Closed
DavideD opened this issue Dec 9, 2021 · 6 comments · Fixed by #1241
Assignees
Labels
bug Something isn't working enhancement New feature or request waiting We are waiting for another PR or issue to be solved before merging this one
Milestone

Comments

@DavideD
Copy link
Member

DavideD commented Dec 9, 2021

Mapping example:

@JoinColumn(name = "device_id", nullable = false)
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Device.class, optional = false)
private Device device;

Setting either nullable = false or optional = false will cause the following exception during a persist:

Caused by: java.lang.UnsupportedOperationException: reactive persistence context
	at org.hibernate.reactive.engine.impl.ReactivePersistenceContextAdapter.getDatabaseSnapshot(ReactivePersistenceContextAdapter.java:76)
	at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:306)
	at org.hibernate.engine.internal.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:230)
	at org.hibernate.engine.internal.ForeignKeys$Nullifier.access$000(ForeignKeys.java:36)
	at org.hibernate.engine.internal.ForeignKeys.collectNonNullableTransientEntities(ForeignKeys.java:414)
	at org.hibernate.engine.internal.ForeignKeys.findNonNullableTransientEntities(ForeignKeys.java:385)
	at org.hibernate.action.internal.AbstractEntityInsertAction.findNonNullableTransientEntities(AbstractEntityInsertAction.java:91)
	at org.hibernate.reactive.engine.ReactiveActionQueue.addInsertAction(ReactiveActionQueue.java:346)
	at org.hibernate.reactive.engine.ReactiveActionQueue.addAction(ReactiveActionQueue.java:331)
@DavideD DavideD added the enhancement New feature or request label Dec 9, 2021
@DavideD DavideD changed the title Persist of entity with non nullable association causes UnsupportedOperationException Persist of entity mapped with a non nullable association causes UnsupportedOperationException Dec 9, 2021
@gavinking gavinking added the bug Something isn't working label Dec 17, 2021
@DavideD DavideD added this to the next milestone Jan 14, 2022
@blafond blafond self-assigned this Jan 25, 2022
@blafond
Copy link
Member

blafond commented Jan 28, 2022

@DavideD I pushed some tests to a branch that replicates the error as well as starts adding the missing implementations to wrap the logic to discover any non-nullable dependent entities.

Got down to ReactiveEntityRegularInsertAction which uses ForeignKeys to find/collect the relevant entities.

I'm stuck right now because most of the implementation on the ORM side is in an internal package. There's already a hibernate ForeignKeys class that is based on the ORM version, but it's incomplete. I started adding the missing logic to it, however, the critical utility class NonNullableTransientDependencies is on the interface and it's internal as well.

Not sure how to proceed to get past the hidden/private/internal ORM code.

I'll ping you first thing Monday ... with more questions :)

@DavideD
Copy link
Member Author

DavideD commented Jan 28, 2022

It's a bit tricky, but at first glance you need to add a method to our ForeignKeys that mimics findNonNullableTransientEntities from the one in Hibernate ORM. The difference is that it will return a CompletionStage<NonNullableTransientDependencies>.

The implementation of this method needs to call the isNullifiable in Reactive (and not the one in ORM).

@blafond
Copy link
Member

blafond commented Jan 28, 2022

My commits start down that road... here.

My roadblock is with ORM's NonNullableTransientDependencies and ForeignKeys internal classes.. they are final and access to NonNullableTransientDependencies.add(String propertyName, Object transientEntity) isn't available. So implementing a reactive ForeignKeys.collectNonNullableTransientEntities(...) to "add" non-nullable entities isn't possible.

@DavideD
Copy link
Member Author

DavideD commented Jan 28, 2022 via email

@DavideD
Copy link
Member Author

DavideD commented Jan 30, 2022

I see now.
You can prepare a PR for Hibernate ORM that change the visibility of the add method and see if they are fine with it.
But the method is package-private, so you don't have to wait for the next ORM realease if you move the class using the method to a package with the same name (org.hibernate.engine.internal).

blafond added a commit to blafond/hibernate-reactive that referenced this issue Feb 3, 2022
blafond added a commit to blafond/hibernate-reactive that referenced this issue Feb 3, 2022
blafond added a commit to blafond/hibernate-reactive that referenced this issue Feb 3, 2022
@DavideD DavideD modified the milestones: 1.1.3.Final, nxt Feb 10, 2022
DavideD pushed a commit to DavideD/hibernate-reactive that referenced this issue Mar 15, 2022
DavideD pushed a commit to DavideD/hibernate-reactive that referenced this issue Mar 15, 2022
@DavideD DavideD modified the milestones: 1.1.4.Final, next Mar 16, 2022
@DavideD DavideD added the waiting We are waiting for another PR or issue to be solved before merging this one label Mar 16, 2022
@DavideD
Copy link
Member Author

DavideD commented Mar 16, 2022

Waiting fo rORM 5.6.7.Final

DavideD pushed a commit to DavideD/hibernate-reactive that referenced this issue Mar 16, 2022
DavideD pushed a commit to DavideD/hibernate-reactive that referenced this issue Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request waiting We are waiting for another PR or issue to be solved before merging this one
Projects
None yet
3 participants