Skip to content

Conversation

@rayudu3745
Copy link
Collaborator

@rayudu3745 rayudu3745 commented Dec 26, 2025

Add support for spanner named schemas https://docs.cloud.google.com/spanner/docs/named-schemas

@rayudu3745 rayudu3745 linked an issue Dec 26, 2025 that may be closed by this pull request
@rayudu3745 rayudu3745 force-pushed the named_schemas branch 3 times, most recently from fe857d7 to d3ef358 Compare December 29, 2025 12:43
@rayudu3745 rayudu3745 marked this pull request as ready for review December 30, 2025 06:51
@rayudu3745 rayudu3745 requested a review from olavloite December 30, 2025 07:27
Comment on lines 62 to 65

String defaultSchema =
(String) options.getConfigurationValues().get(AvailableSettings.DEFAULT_SCHEMA);

Copy link
Contributor

Choose a reason for hiding this comment

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

nit (here and elsewhere): I don't think we need to introduce empty lines before every occurrence of defaultSchema. Would you mind taking a second look where it makes sense to break up the code a bit, and where it is not needed (e.g. I think that having this line of code separated by an empty line both before and after is a bit too much)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines -285 to +286
"drop table `Employee`",
"drop table `Employee_Sequence`",
"drop table Employee",
"drop table Employee_Sequence",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this change remove identifier quoting? I think that this might break existing customers who use table names that contain reserved keywords.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed how the name is rendered correctly with sqlContext.format method ,
quoting will still be applied by hibernate to identifier when required like if sqlkeyword is used, here it is not required

there is fix regarding this which i added to SpannerDialect in hibernate repository recently but that is not released yet, so added that fix here as well now
also added a test to verify the quotes are applied when a key word is applied

IntStream.range(0, fetchSize)
.mapToObj(
ignore -> "nextval('" + sequenceName.getSequenceName().getText() + "') as n")
.mapToObj(ignore -> "nextval('" + sequenceName.render() + "') as n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have any tests that verify that this works? If I understand it correctly, it will generate a statement like select next('my_schema.my_sequence') as n. Is that correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes , correct
there is a test for this in NamedSchemaIT test

The Cloud Spanner Dialect supports named schemas. You can organize your tables into specific Spanner schemas using the standard JPA/Hibernate mechanisms. For more information on Spanner Named Schemas, please refer to the https://docs.cloud.google.com/spanner/docs/named-schemas[official documentation].

You can specify a schema for a specific entity using the `schema` attribute of the `@Table` annotation:

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should add a note here that named schemas cannot (currently) be used to implement a multi-tenancy strategy, as Spanner does not support a 'search_path' or similar property.

More background information:
See this blog for an example for how that can be used with PostgreSQL: https://vladmihalcea.com/hibernate-database-schema-multitenancy/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, added a not saying schema based multi-tenancy is not supported
we might have to support sql statements like 'set schema' in driver, will look into it more if customer asks for it

@rayudu3745 rayudu3745 requested a review from olavloite December 30, 2025 11:45
@rayudu3745 rayudu3745 merged commit 1267049 into GoogleCloudPlatform:master Jan 5, 2026
7 checks passed
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.

Feature Request: Support Spanner named schemas.

2 participants