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

new @SQLSelect annotation does not work #1627

Closed
gavinking opened this issue May 13, 2023 · 4 comments · Fixed by #1721
Closed

new @SQLSelect annotation does not work #1627

gavinking opened this issue May 13, 2023 · 4 comments · Fixed by #1721
Assignees
Labels
bug Something isn't working
Milestone

Comments

@gavinking
Copy link
Member

If I add:

@SQLSelect(sql = "select name, id from authors where id = $1")

to org.hibernate.reactive.example.nativesql.Author, I get:

Exception in thread "main" java.util.NoSuchElementException
	at java.base/java.util.Collections$EmptyIterator.next(Collections.java:4210)
	at java.base/java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1047)
	at org.hibernate.reactive.loader.ast.internal.ReactiveSingleIdEntityLoaderProvidedQueryImpl.load(ReactiveSingleIdEntityLoaderProvidedQueryImpl.java:51)
	at org.hibernate.reactive.loader.ast.internal.ReactiveSingleIdEntityLoaderProvidedQueryImpl.load(ReactiveSingleIdEntityLoaderProvidedQueryImpl.java:27)
	at org.hibernate.reactive.persister.entity.impl.ReactiveAbstractPersisterDelegate.load(ReactiveAbstractPersisterDelegate.java:235)
	at org.hibernate.reactive.persister.entity.impl.ReactiveSingleTableEntityPersister.doReactiveLoad(ReactiveSingleTableEntityPersister.java:272)

This issue appears to be that the $1 is not recognized. But changing it to ? or ?1 does not seem to help.

@blafond blafond self-assigned this Jul 11, 2023
blafond added a commit to blafond/hibernate-reactive that referenced this issue Jul 12, 2023
@blafond
Copy link
Member

blafond commented Jul 12, 2023

@davide Pushed a commit of a Reactive version of ORM's SQLSelectTest to my repo: blafond@e88effd on a 1627-sqlselect branch

I think the current errors are due to two things that are missing in Reactive.

  1. During the ReactiveSingleIdEntityLoaderProvidedQueryImpl.load() call, the query object is an instance of a AbstractSelectionQuery rather than a ReactiveAbstractSelectionQuery so query.uniqueResult() is called rather than the reactive method: reactiveUnique(). This is probably due to ReactiveNamedNativeQueryMomento not being created, but NamedNativeQueryMomento instead.
  2. The parameter parsing for AbstractSelectionQuery is using the ORM's ParameterParser which only looks for the ? placeholder ... so using $1 won't work

@DavideD
Copy link
Member

DavideD commented Jul 13, 2023

I gave a look and it seems to happen because we don't wrap the NamedObjectRepository into a ReactiveNamedObjectRepository in ReactiveAbstractPersisterDelegate#createReactiveSingleIdEntityLoader. I haven't looked too much into it, but I think we should add a ReactiveQueryEngine that takes care of this thing. Or, as a quick alternative, something like:

 NamedObjectRepository namedObjectRepository = factory.getQueryEngine().getNamedObjectRepository();
final NamedQueryMemento namedQueryMemento = new ReactiveNamedObjectRepositoryImpl( namedObjectRepository )

We also need to wrap the result of ReactiveNamedObjectRepositoryImpl.java#resolve. Otherwise it won't return a reactive query.

@DavideD
Copy link
Member

DavideD commented Jul 13, 2023

Also, this seems very wrong:

@blafond
Copy link
Member

blafond commented Jul 13, 2023

thx.. been working on this and pushed a couple changes more changes.

blafond added a commit to blafond/hibernate-reactive that referenced this issue Jul 14, 2023
blafond added a commit to blafond/hibernate-reactive that referenced this issue Jul 14, 2023
blafond added a commit to blafond/hibernate-reactive that referenced this issue Jul 17, 2023
blafond added a commit to blafond/hibernate-reactive that referenced this issue Jul 17, 2023
blafond added a commit to blafond/hibernate-reactive that referenced this issue Jul 17, 2023
blafond added a commit to blafond/hibernate-reactive that referenced this issue Jul 17, 2023
DavideD pushed a commit to DavideD/hibernate-reactive that referenced this issue Jul 25, 2023
DavideD pushed a commit to DavideD/hibernate-reactive that referenced this issue Jul 25, 2023
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jul 25, 2023
I think we can remove the association of embeddable for the
sake of making the test simpler
@DavideD DavideD added this to the 2.0.4.Final milestone Jul 25, 2023
@DavideD DavideD added the bug Something isn't working label Jul 25, 2023
DavideD pushed a commit that referenced this issue Jul 25, 2023
DavideD added a commit that referenced this issue Jul 25, 2023
I think we can remove the association of embeddable for the
sake of making the test simpler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants