question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Spanner Data] Accessing custom repository methods within a readWrite transaction

See original GitHub issue

Is your feature request related to a problem? Please describe. Transaction management is essential for creating reliable applications. Spanner allows us to create an interface and add custom methods for example by creating new method following naming conventions.

For example:

deleteByColumn(String columnValue)

Based on the name, Spanner data will execute a delete query and delete every row where column == columnValue.

For transaction management, we prefer programmatic transaction management calling the method on the SpannerRepository

performReadWriteTransaction

Unfortunately, this method returns

SpannerRepository<T, ID> that does not provide us custom methods, that we added to our custom repository interface. Therefore, the usage of custom-added methods on a repository is limited.

Describe the solution you’d like Adapt the spanner data implementation and update performReadWriteTransaction to get a function with a parameter type of the custom subclass. This could be done with generics, but the actual implementation of the parent class and related parts need to be adapted. Also, this is not a breaking change because customers of spring data anyhow can for now only use SpannerRepository methods. The new way would require that the interface extends SpannerRepository, therefore, it should not break any build.

In short, the combination of custom repository and programmatic transaction handling should work without any limitations. It’s a key selling point of Spanner and part of every application.

Describe alternatives you’ve considered For now, we try to use methods of the SpannerRepository base class and avoid many custom methods in case if we need to group multiple executions within a single transaction. If this is really needed, we will try to fall back to SpannerOperations and execute queries manually using the SpannerTemplate.

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dzoucommented, Aug 13, 2021

Thanks for the clarifications @sebarthel89. I will share this with our team internally to discuss more about priority and how to fix.

0reactions
sebarthel89commented, Aug 24, 2021

Good point! I would suggest you add it to the documentation and to the spring boot example. This is very useful !

Thank you, keep up the good work 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

About transactions | Cloud Spanner
A transaction in Spanner is a set of reads and writes that execute atomically at a single logical point in time across columns,...
Read more >
157. Spring Data Cloud Spanner
Described in the following sections, these are methods residing in your custom repository interfaces of which implementations are generated based on their names ......
Read more >
Spring Cloud GCP
Map objects, relationships, and collections with Spring Data Cloud Spanner, Spring Data Cloud Datastore and Spring Data Reactive Repositories for Cloud ...
Read more >
About Cloud Spanner - Go Packages
Read-only transactions cannot change the database, do not acquire locks, and may access either the current database state or states in the past....
Read more >
SpannerRepository (Spring Cloud GCP 2.0.2 API)
Performs multiple read and write operations in a single transaction. Methods inherited from interface org.springframework.data.repository.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found