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

Hibernate Reactive requires a Jdbc env? #2266

Closed
hantsy opened this issue Jun 9, 2023 · 7 comments
Closed

Hibernate Reactive requires a Jdbc env? #2266

hantsy opened this issue Jun 9, 2023 · 7 comments
Assignees

Comments

@hantsy
Copy link

hantsy commented Jun 9, 2023

Expected Behavior

I tried to update my micronaut hibernate reactive to 4.0.0-M3, but the application context loading failed, it seems it requires a jdbc env.

The existing config does not work:

https://github.com/hantsy/micronaut-sandbox/blob/master/data-hibernate-reactive/src/main/resources/application.yml#L4-L15

Actual Behaviour

Bean definition [org.hibernate.SessionFactory] could not be loaded: 
Error instantiating bean of type  [org.hibernate.boot.SessionFactoryBuilder]

Message: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: 
Cannot invoke "String.length()" because "path" is null
Path Taken: SessionFactoryPerJpaConfigurationFactory.buildHibernateSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) --> 
SessionFactoryPerJpaConfigurationFactory.buildHibernateSessionFactoryBuilder([SessionFactoryBuilder sessionFactoryBuilder]) --> 
SessionFactoryPerJpaConfigurationFactory.buildHibernateSessionFactoryBuilder([Metadata metadata],JpaConfiguration jpaConfiguration)

io.micronaut.context.exceptions.BeanInstantiationException: 
Bean definition [org.hibernate.SessionFactory] 
could not be loaded: Error instantiating bean of type  [org.hibernate.boot.SessionFactoryBuilder]

Steps To Reproduce

No response

Environment Information

Windows 10 Pro, Java 17

Example Application

https://github.com/hantsy/micronaut-sandbox/tree/master/data-hibernate-reactive

Version

4.0.0-M3

@radovanradic radovanradic self-assigned this Jun 9, 2023
@radovanradic
Copy link
Contributor

Changing application-test.yml to this:

jpa.default.properties.hibernate.connection.db-type: postgres
jpa.default.properties.hibernate.hbm2ddl.auto: create-drop
jpa.default.reactive: true

should resolve the issue (this is what micronaut launch in 4.0.0-M3 generates as well). I think test resources don't expect url to be defined, need to have db-type so it will initialize rest of the config stuff for hibernate.

@hantsy
Copy link
Author

hantsy commented Jun 9, 2023

The application-test.yml will override the default values in application.yml? These properties are set in application.yml.

https://github.com/hantsy/micronaut-sandbox/blob/master/data-hibernate-reactive/src/main/resources/application.yml

@radovanradic
Copy link
Contributor

Don't think this worked with hibernate reactive 1.x either as I am getting this error when trying your config

Caused by: org.hibernate.HibernateException: HR000049: Could not determine Dialect from connection URI: 'jdbc:tc:postgresql:14:///postgres' (specify a connection URI with scheme 'postgresql:', 'mysql:', 'cockroachdb', or 'db2:')

and in hibernate reactive 2 the error you posted

Caused by: java.lang.NullPointerException: Cannot invoke "String.length()" because "path" is null
at org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration.connectOptions(DefaultSqlClientPoolConfiguration.java:98)

because this URI jdbc:tc:postgresql:14:///postgres is not supported/expected by the hibernate reactive

public SqlConnectOptions connectOptions(URI uri) {
		String scheme = uri.getScheme();
		String path = scheme.equals( "oracle" )
				? oraclePath( uri )
				: uri.getPath();

		String database = path.length() > 0
				? path.substring( 1 )
				: "";

variable path is null here. So I think the way to go is via test resources or perhaps ask in hibernate reactive about tc url.

@hantsy
Copy link
Author

hantsy commented Jun 9, 2023

Don't think this worked with hibernate reactive 1.x either as I am getting this error when trying your config

The original sample codes(3.9.3), only one example failed due to a tx issue. #1837

I tried to switch to use test-resource in data-r2dbc example, encountered another new issue. micronaut-projects/micronaut-test-resources#313

@radovanradic
Copy link
Contributor

Ok, previous comment is maybe unrelated to this issue. My point is hibernate reactive won't support url starting with jdbc:tc: so that needs to be changed. I said that was not supported in earlier reactive hibernate (or micronaut 3.x)

@hantsy
Copy link
Author

hantsy commented Jun 9, 2023

All my original codes used test containers directly.

Ok, I cleaned up the hibernate reactive example, use test-resource instead(leave url, username, password null, and remove testcontainers), encountered the same issue. micronaut-projects/micronaut-test-resources#313

@hantsy
Copy link
Author

hantsy commented Jun 9, 2023

Ok, previous comment is maybe unrelated to this issue.

Close this issue.

@hantsy hantsy closed this as completed Jun 9, 2023
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

2 participants