Skip to content

HHH-15283 - fix NPE for NamedNativeQuery + SqlResultSetMapping (columns) #5055

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

Conversation

NathanQingyangXu
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu commented May 14, 2022

https://hibernate.atlassian.net/browse/HHH-15283

This bug was from https://hibernate.atlassian.net/browse/HHH-15070, a suite of bug reports submitted by Spring Data JPA team member for their Hibernate v6 support (see spring-projects/spring-data-jpa#2423 (comment))

This PR aim to solve one confirmed bug; there might be other PRs for the same ticket.

Seems another NPE bug. In the following entity:

	@SqlResultSetMapping(
		name = "mapping",
		columns = @ColumnResult( name = "cnt" )
	)
	@NamedNativeQuery(
		name = "sample.count",
		resultSetMapping = "mapping",
		query = "SELECT count(*) AS cnt FROM Sample"
	)
	@Entity(name = "Sample")
	static class Sample {

		@Id
		@GeneratedValue
		Long id;

	}

At least two classes' NPE issues are exposed.

@NathanQingyangXu NathanQingyangXu force-pushed the HHH-15070-1 branch 4 times, most recently from d0b3eb8 to 2cb1134 Compare May 15, 2022 21:53
@NathanQingyangXu NathanQingyangXu marked this pull request as draft May 16, 2022 11:03
@NathanQingyangXu NathanQingyangXu marked this pull request as ready for review May 16, 2022 22:10
@dreab8
Copy link
Member

dreab8 commented May 18, 2022

Hi @NathanQingyangXu ,

it seems to me that https://hibernate.atlassian.net/browse/HHH-15070 targets only https://github.com/odrotbohm/hibernate-bugs/tree/main/h6-embedded-id-record Custom EmbeddedInstantiator not considered for embedded identifier types so I think it is better if you create a specific Jira for this PR.

Thanks

@NathanQingyangXu
Copy link
Contributor Author

Hi @NathanQingyangXu ,

it seems to me that https://hibernate.atlassian.net/browse/HHH-15070 targets only https://github.com/odrotbohm/hibernate-bugs/tree/main/h6-embedded-id-record Custom EmbeddedInstantiator not considered for embedded identifier types so I think it is better if you create a specific Jira for this PR.

Thanks

Yeah, I tested all the bugs under https://github.com/odrotbohm/hibernate-bugs, but I agree we'd better create a new ticket for better tracking.

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented May 19, 2022

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@NathanQingyangXu NathanQingyangXu changed the title HHH-15070 - fix NPE for NamedNativeQuery + SqlResultSetMapping (columns) HHH-15283 - fix NPE for NamedNativeQuery + SqlResultSetMapping (columns) May 19, 2022
@NathanQingyangXu
Copy link
Contributor Author

NathanQingyangXu commented May 19, 2022

I created a new ticket here: https://hibernate.atlassian.net/browse/HHH-15283 and explained its relationship with https://hibernate.atlassian.net/browse/HHH-15070. The git commit message prefix was also changed.

@dreab8
Copy link
Member

dreab8 commented May 19, 2022

Thanks @NathanQingyangXu

@odrotbohm
Copy link

Thanks, folks, for spending time with this. As Nathan correctly spotted, the repo lined in the ticket indeed contains reproduces for quite a few issues we found. That said, each of the folders in that repo already has a ticket filed. We usually point to the folder within the repository for each ticket. A quick search for odrotbohm/hibernate-bugs reveals this.

@NathanQingyangXu
Copy link
Contributor Author

Thanks, folks, for spending time with this. As Nathan correctly spotted, the repo lined in the ticket indeed contains reproduces for quite a few issues we found. That said, each of the folders in that repo already has a ticket filed. We usually point to the folder within the repository for each ticket. A quick search for odrotbohm/hibernate-bugs reveals this.

Yeah, this link points to the new ticket I just created.

@dreab8
Copy link
Member

dreab8 commented May 19, 2022

I'm going to close https://hibernate.atlassian.net/browse/HHH-15070, as explained by @NathanQingyangXu it is fixed in 6.0.1.Final

@odrotbohm
Copy link

That's nice, thanks Andrea! I'm going to take a round through the reproducer repo and document the latest state of them in readmes of each of the modules.

@dreab8
Copy link
Member

dreab8 commented May 19, 2022

Thnaks @odrotbohm

@dreab8
Copy link
Member

dreab8 commented May 19, 2022

@NathanQingyangXu I have made a little change to this PR #5064, what do you think?

@odrotbohm
Copy link

I'm going to close https://hibernate.atlassian.net/browse/HHH-15070, as explained by @NathanQingyangXu it is fixed in 6.0.1.Final

Unfortunately, the issue is not gone. I've updated the reproducer, and it still fails, not applying the custom EmbeddableInstantiator.

@dreab8
Copy link
Member

dreab8 commented May 19, 2022

I think the issue is the use of record for the UserId

@NathanQingyangXu
Copy link
Contributor Author

NathanQingyangXu commented May 19, 2022 via email

@odrotbohm
Copy link

Which I create and register a custom EmbeddableInstantiator for, which is not used. That is precisely what the ticket is about. UserId is an embeddable. EmbeddableInstantiators can be registered to customize their instantiation. Still, it is not used when used as id. It is used when UserId is used as non-id property (the test gets green if you try).

That also shows that the fact that the class is a record, is not the culprit. In fact, records not working as embeddables, out of the box is the driver behind this ticket.

(I apologize for hijacking this ticket, but I unfortunately cannot comment on tickets in your JIRA.)

@NathanQingyangXu
Copy link
Contributor Author

NathanQingyangXu commented May 19, 2022 via email

@dreab8
Copy link
Member

dreab8 commented May 19, 2022

I tried and yes it happend that if you do not use the record the test is green but it is true that the EmbeddableInstantiator is not called, so I'm going to re-open the Jira.

Thanks @odrotbohm and @NathanQingyangXu

@dreab8
Copy link
Member

dreab8 commented May 19, 2022

Thanks @NathanQingyangXu ,

I'm going to close this in favour of #5064

@dreab8 dreab8 closed this May 19, 2022
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