Skip to content

HHH-15618 Accept TypedParameterValue for procedure #5438

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

Merged
merged 1 commit into from
Dec 22, 2022

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Oct 21, 2022

@quaff
Copy link
Contributor Author

quaff commented Nov 7, 2022

Could anyone review this?

@beikov
Copy link
Member

beikov commented Nov 7, 2022

I don't see a reason for this PR. There is an explicit API that can be used to bind parameters in a typed fashion. Also, TypedParameterValue is usually handled on the Query level, so if we do this at all, it should be handled in ProcedureCallImpl. Also, it's nice that you provide an implementation for 5.6, but we also need a test and possible fix for the main branch.

@quaff
Copy link
Contributor Author

quaff commented Nov 9, 2022

I don't see a reason for this PR. There is an explicit API that can be used to bind parameters in a typed fashion. Also, TypedParameterValue is usually handled on the Query level, so if we do this at all, it should be handled in ProcedureCallImpl. Also, it's nice that you provide an implementation for 5.6, but we also need a test and possible fix for the main branch.

@beikov Updated as you suggested.

@gregturn
Copy link

Adopting Hibernate's TypedParameterValue wrapper is causing things to break in other places as that wrapper type percolates through our code. A big one our community runs into is stored procedures.

With @quaff having offered a patch in the location your cited, what are the odds you could merge this patch?

gregturn added a commit to spring-projects/spring-data-jpa that referenced this pull request Dec 19, 2022
Hibernate supports TypedParameterValue in queries, but not stored procedures.

Until hibernate/hibernate-orm#5438 is adopted, we have to dereference such parameters on our end first.

Closes #2544.
gregturn added a commit to spring-projects/spring-data-jpa that referenced this pull request Dec 19, 2022
Hibernate supports TypedParameterValue in queries, but not stored procedures.

Until hibernate/hibernate-orm#5438 is adopted, we have to dereference such parameters on our end first.

Closes #2544.
gregturn added a commit to spring-projects/spring-data-jpa that referenced this pull request Dec 19, 2022
Hibernate supports TypedParameterValue in queries, but not stored procedures.

Until hibernate/hibernate-orm#5438 is adopted, we have to dereference such parameters on our end first.

Closes #2544.
@gregturn
Copy link

Regarding Hibernate 6.1, it appears to already be handled way up the hierarchy in AbstractCommonQueryContract.

	@Override
	public CommonQueryContract setParameter(int position, Object value) {
		if ( value instanceof TypedParameterValue ) {
			@SuppressWarnings("unchecked")
			final TypedParameterValue<Object> typedValue = (TypedParameterValue<Object>) value;
			final BindableType<Object> type = typedValue.getType();
			if ( type != null ) {
				return setParameter( position, typedValue.getValue(), type );
			}
			else {
				return setParameter( position, typedValue.getValue(), typedValue.getTypeReference() );
			}
		}

		final QueryParameterImplementor<?> param = getParameterMetadata().getQueryParameter( position );

		if ( param == null ) {
			throw new IllegalArgumentException( "Positional parameter [" + position + "] is not registered with this procedure call" );
		}

		if ( param.allowsMultiValuedBinding() ) {
			final BindableType<?> hibernateType = param.getHibernateType();
			if ( hibernateType == null || isInstance( hibernateType, value ) ) {
				if ( value instanceof Collection && !isRegisteredAsBasicType( value.getClass() ) ) {
					//noinspection rawtypes,unchecked
					return setParameterList( param, (Collection) value );
				}
			}
		}

		locateBinding( position ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() );
		return this;
	}

gregturn added a commit to spring-projects/spring-data-jpa that referenced this pull request Dec 19, 2022
Hibernate 6.1 properly handles TypeParameterValue for general parameters, but not for temporal ones. So we must dereference in those scenarios.

Related: #2544, hibernate/hibernate-orm#5438
gregturn added a commit to spring-projects/spring-data-jpa that referenced this pull request Dec 19, 2022
Hibernate 6.1 properly handles TypeParameterValue for general parameters, but not for temporal ones. So we must dereference in those scenarios.

Related: #2544, hibernate/hibernate-orm#5438
gregturn added a commit to spring-projects/spring-data-jpa that referenced this pull request Dec 19, 2022
Hibernate 6.1 properly handles TypeParameterValue for general parameters, but not for temporal ones. So we must dereference in those scenarios.

Related: #2544, hibernate/hibernate-orm#5438
@beikov
Copy link
Member

beikov commented Dec 20, 2022

Updated as you suggested.

@quaff the changes look good, but please also create a PR against the main branch. Chances are good that we will merge this also for 5.6 @gregturn

@quaff
Copy link
Contributor Author

quaff commented Dec 21, 2022 via email

@beikov
Copy link
Member

beikov commented Dec 21, 2022

But it needs at least a test case to verify it works correctly.

@quaff
Copy link
Contributor Author

quaff commented Dec 21, 2022

But it needs at least a test case to verify it works correctly.

@beikov I've created #5819.

@beikov beikov merged commit 49fbe84 into hibernate:5.6 Dec 22, 2022
@beikov
Copy link
Member

beikov commented Dec 22, 2022

Thanks!

gregturn added a commit to spring-projects/spring-data-jpa that referenced this pull request Apr 28, 2023
Hibernate resolved hibernate/hibernate-orm#5438, allowing us to no longer implement special handling.

Resolves #2902.
schauder pushed a commit to spring-projects/spring-data-jpa that referenced this pull request May 2, 2023
Hibernate resolved hibernate/hibernate-orm#5438, allowing us to no longer implement special handling.

Closes #2902
Original pull request #2933
trayanus1026 pushed a commit to trayanus1026/spring-data-jpa-java that referenced this pull request Aug 5, 2023
Hibernate 6.1 properly handles TypeParameterValue for general parameters, but not for temporal ones. So we must dereference in those scenarios.

Related: #2544, hibernate/hibernate-orm#5438
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

Successfully merging this pull request may close these issues.

3 participants