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

Reactive hibernate version 1.0.0.CR9 throws an exception while opening session #926

Closed
nivinps opened this issue Aug 3, 2021 · 8 comments

Comments

@nivinps
Copy link

nivinps commented Aug 3, 2021

Hi,
I am using Hibernate Reactive for my spring webflux project. I have upgraded hibernate reactive version from 1.0.0.CR7 to 1.0.0.CR9, after that I am getting an exception while opening session. Kindly help.

Earlier working versions:

Hibernate Reactive - 1.0.0.CR7
vertx-mysql-client - 4.1.0
Spring boot version - 2.5.3

Mutiny.SessionFactory sessionFactory = emf.unwrap(Mutiny.SessionFactory.class);
Mutiny.Session session = sessionFactory.openSession(); //working

Upgraded versions:

Hibernate Reactive - 1.0.0.CR9
vertx-mysql-client - 4.1.2
Spring boot version - 2.5.3

Mutiny.SessionFactory sessionFactory = emf.unwrap(Mutiny.SessionFactory.class);
Mutiny.Session session = sessionFactory.openSession(); //throwing an exception

Exception Message:
HR000068: This method should exclusively be invoked from a Vert.x EventLoop thread; currently running on thread 'reactor-http-nio-3'; nested exception is java.lang.IllegalStateException: HR000068: This method should exclusively be invoked from a Vert.x EventLoop thread; currently running on thread 'reactor-http-nio-3'

@DavideD
Copy link
Member

DavideD commented Aug 3, 2021

See if this answer your question: #750 (comment)

@DavideD
Copy link
Member

DavideD commented Aug 3, 2021

The reason you are having this error is because we have added some checks to make sure that the session is used correctly.
The simplest solution would be to use sessionFactory.withSession or sessionFactory.withTransaction, in those cases Hibernate Reactive will take care of the issue automatically.

@nivinps
Copy link
Author

nivinps commented Aug 4, 2021

Thank you @DavideD for your response. In my project I have used several places as sessionFactory.openSession(). Anywy I will change those things. Hereafter I will use sessionFactory.withSession or sessionFactory.withTransaction. No need to close the session while using this. So that is an added advantage :)

I changed my code like this

 String queryString = "select c.country_name as country_name, c.phone_code as phone_code from erp_country c"; // MySql query
 List<Object[]> list = sessionFactory.withSession(s->s.createNativeQuery(queryString).getResultList()).await().indefinitely(); //Compilation error

But I am getting one compilation issue over here. If I did not pass the second argument in the native query method then it should return list of object array right. But it is returning as list of object.
In my Intelli J idea it is showing 'provided' as List<Object>. But 'required type' is List<Object[]>

Hibernate Reactive - 1.0.0.CR9
vertx-mysql-client - 4.1.2
Spring boot version - 2.5.3

@gavinking
Copy link
Member

@nivinps you should use the overloaded version of createNativeQuery() which accepts a Class representing the return type.

@nivinps
Copy link
Author

nivinps commented Aug 4, 2021

okay. Is it related to this #919 issue. Because 1.0.0.CR9 version will give a cast exception if I pass second argument as Tuple.class. So I just try to get as list of object array in this version (1.0.0.CR9)

@DavideD
Copy link
Member

DavideD commented Aug 4, 2021

The Tuple class will be supported in the next release but you should be able to use Object[].class as second parameter in this one:

s.createNativeQuery(queryString, Object[].class).getResultList()

@nivinps
Copy link
Author

nivinps commented Aug 4, 2021

Thanks @DavideD. It is working

@DavideD
Copy link
Member

DavideD commented Aug 4, 2021

I think we can consider this issue closed.
Thanks @nivinps and @gavinking

@DavideD DavideD closed this as completed Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants