-
Notifications
You must be signed in to change notification settings - Fork 319
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
Transaction error using Spanner JDBC with JPA and Spring Cloud GCP Datastore in the same project #944
Comments
I tested with another application that doesn't use the Datastore itself but had the For some reason it is not necessary to have the starter dependency In this second application I just removed the
It makes me think if the problem is with the datastore dependency itself or with the JPA starter auto configurations not being configured properly because of the datastore dependency. |
The second issue is because Spring Cloud GCP autoconfiguration for Datastore triggers as soon as the client library is detected. Let me think through whether this conflict (Spanner with JPA, but Datastore with a custom Spring Data implementation) can be avoided in a sensible way. Are you using Datastore repositories, or just the template to read data? In the meantime, turn off |
I did not look into it, and I am going on vacation; someone else will pick this up. @lucasoares Did disabling datastore autoconfiguration mitigate the issue for you? |
This is also happening for me, using only JPA + Datastore. Disabling the autoconfiguration is a workaround I guess, but not that nice. It started happening after upgrading the spring-cloud-gcp-data-datastore, from 1.2.8.RELEASE, where the error was not present, to 2.0.10 where it is. I also tried going to the last version 3.2.1, but the same error is still there. |
I did not tried it, but in my use case this is not possible because I need the datastore. In the other project I had only the I don't think the problem is the autoconfiguration itself, since it comes from the |
@zhumin8 Could you reproduce this and reason about what's going on here? |
For those who have the issue with Jpa + datastore you can workaround the issue by declaring in your own configuration the two transaction manager. @Configuration
public class MixingJpaAndDatastoreConfiguration
{
// ============================================================ //
// ========================== DATASTORE ======================= //
// ============================================================ //
@Bean
@ConditionalOnMissingBean(name = "datastoreTransactionManager")
public DatastoreTransactionManager datastoreTransactionManager(final DatastoreProvider datastore,
final ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers)
{
final TransactionManagerCustomizers transactionManagerCustomizers1 = transactionManagerCustomizers.getIfAvailable();
final DatastoreTransactionManager transactionManager = new DatastoreTransactionManager(datastore);
if (transactionManagerCustomizers1 != null)
{
transactionManagerCustomizers1.customize(transactionManager);
}
return transactionManager;
}
// ============================================================ //
// =========================== MYSQL ========================== //
// ============================================================ //
@Bean
@ConditionalOnMissingBean(name = "transactionManager")
public PlatformTransactionManager transactionManager(final ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers)
{
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManagerCustomizers.ifAvailable((customizers) ->
{
customizers.customize(transactionManager);
});
return transactionManager;
}
} You will need to specify on your @transactional which manager you want but you will have both available. For example, jpa transaction will need @transactional(transactionManager = "transactionManager"). |
…#1412) Fixes #944 Conditional for Spanner is based on missing beans of type SpannerTransactionManager instead of PlatformTransactionManager, this way it always gets created if Spanner libs are pulled in Conditional for Datastore is based on missing beans of type DatastoreTransactionManager instead of PlatformTransactionManager, this way it gets created if Datastore libs are pulled in. It is the user's responsibility to designate the transaction's right transaction manager: ``` @transactional(transactionManager = "spannerTransactionManager") ``` ``` @transactional(transactionManager = "datastoreTransactionManager") ```
…#1412) Fixes #944 Conditional for Spanner is based on missing beans of type SpannerTransactionManager instead of PlatformTransactionManager, this way it always gets created if Spanner libs are pulled in Conditional for Datastore is based on missing beans of type DatastoreTransactionManager instead of PlatformTransactionManager, this way it gets created if Datastore libs are pulled in. It is the user's responsibility to designate the transaction's right transaction manager: ``` @transactional(transactionManager = "spannerTransactionManager") ``` ``` @transactional(transactionManager = "datastoreTransactionManager") ```
Hello.
I'm trying to configure a single project using Spring Data JPA + Spanner using JDBC connector and also the Spring Cloud GCP Datastore support.
I'm able to read data from both Spanner and Datastore even tho they are located in different GCP projects. The problem is when I try to save any entity (or perform a primary key operation which have a transaction behind the scenes) I get the following error:
I'm basically reading data from Datastore and saving data into Spanner.
Code throwing error:
Repository implementation:
My project configuration (only what matters for this specific error):
WIth these properties:
I can't use Spanner from Spring Cloud GCP because I already have a project using JPA and now I need to access datastore in the same project to copy data to Spanner.
If I remove the
spring-cloud-gcp-starter-data-datastore
dependency from the project (and comment all codes using datastore) I can save data into the Spanner instance without errors.The text was updated successfully, but these errors were encountered: