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

Support converting underscores column name to camel case property name for projecting native query #3472

Closed
wants to merge 1 commit into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented May 13, 2024

By default, Spring Boot configures the physical naming strategy with CamelCaseToUnderscoresNamingStrategy.

Then we should convert underscores back to camel case.

Fix GH-3462

@@ -378,6 +403,14 @@ public boolean containsKey(Object key) {
tuple.get((String) key);
return true;
} catch (IllegalArgumentException e) {
if (nativeQuery) {
try {
tuple.get(JdbcUtils.convertPropertyNameToUnderscoreName((String) key));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of customizing the Map, it would make sense to have a custom Tuple wrapper that handles the conversion.

Consider a tuple that would contain first_name and firstName elements. It is impossible to tell in which order these should appear in a map nor which value to return in a Set<Map.Entry>.

Attempting snake-case to camel-case conversion on value absence makes sense, for the rest we should keep the functionality as-is.

The Tuple wrapper would delegate all enumerative calls to the Tuple delegate while get(…) calls are augmented for property name conversion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated now, please review again.

…e for projecting native query

> By default, Spring Boot configures the physical naming strategy with CamelCaseToUnderscoresNamingStrategy.

Then we should convert underscores back to camel case.

Fix spring-projectsGH-3462
mp911de pushed a commit that referenced this pull request May 14, 2024
mp911de added a commit that referenced this pull request May 14, 2024
Tweak naming, simplify implementation.

See #3462
Original pull request: #3472
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 14, 2024
@mp911de mp911de added this to the 3.3 GA (2024.0.0) milestone May 14, 2024
@mp911de
Copy link
Member

mp911de commented May 14, 2024

Thank you for your contribution. That's merged and polished now.

@mp911de mp911de closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add camelCase to snake_case fallback for native query projections
3 participants