Skip to content

DatabaseSelection is not allways used #2234

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
VladoKuruc opened this issue Apr 16, 2021 · 5 comments
Closed

DatabaseSelection is not allways used #2234

VladoKuruc opened this issue Apr 16, 2021 · 5 comments
Assignees
Labels
type: bug A general bug

Comments

@VladoKuruc
Copy link

After upgrade to SDN 6.1.0 I have Issue with DatabaseSelection.

I use an existing database for unit tests, so I do not create a database in them. I just need to clean up the data at the beginning of the transaction and with the rollback at the end so that testing does not affect the existing data.

In version 6.0.x, I had to use the .in(databaseName) clause.

neo4jClient.query("MATCH (n) DETACH DELETE n").in("neo4jtest").run();

DatabaseSelectionProvider is now available in version 6.1.x in neo4jClient, so it would be nice not to use it.
In this case, an error occurs.

java.lang.IllegalStateException: There is already an ongoing Spring transaction for 'neo4jtest', but you request the default database

However, the same error occurs in the case of a more complex mapping during repository.save () in a transaction where I cannot influence it.
Take a look at the attached unittest where I use the modified AltHobby class. I added two properties there.

DatabaseSelectionProviderIT.java.txt

	@Relationship(type = "CHILD", direction = Relationship.Direction.INCOMING)
	private List<AltHobby> memberOf = new ArrayList<>();

	@Relationship(type = "CHILD", direction = Relationship.Direction.OUTGOING)
	private List<AltHobby> childs = new ArrayList<>(); 

	public List<AltHobby> getMemberOf() {
		return memberOf;
	}
	
	public List<AltHobby> getChilds() {
		return childs;
	} 

Thank for investigation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 16, 2021
@meistermeier
Copy link
Collaborator

Many thanks for reporting this. There seems to be one code path that does not take the DatabaseSelectionProvider into consideration.

@meistermeier meistermeier self-assigned this Apr 17, 2021
@meistermeier meistermeier added bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 17, 2021
meistermeier added a commit that referenced this issue Apr 17, 2021
@meistermeier
Copy link
Collaborator

There should be now a snapshot be available: 6.1.1-GH-2234-SNAPSHOT with a (first) solution.

@VladoKuruc
Copy link
Author

Thank you very much for the quick solution.
The mentioned unit test is already passing. Also my real test with a more complex model.
But I have another issue not directly related to this. If I have Set instead of List relationships, I get an error
java.lang.ClassCastException: Cannot cast java.util.ArrayList to java.util.Set at java.lang.invoke.MethodHandleImpl.newClassCastException(MethodHandleImpl.java:361) at java.lang.invoke.MethodHandleImpl.castReference(MethodHandleImpl.java:356) at org.springframework.data.neo4j.integration.shared.common.AltHobby_Accessor_6ib4k1.setProperty(Unknown Source) at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor.setProperty(InstantiationAwarePropertyAccessor.java:104) at org.springframework.data.neo4j.core.RelationshipHandler.applyFinalResultToOwner(RelationshipHandler.java:130) at org.springframework.data.neo4j.core.Neo4jTemplate.lambda$processNestedRelations$24(Neo4jTemplate.java:730) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:387) at org.springframework.data.neo4j.core.Neo4jTemplate.processNestedRelations(Neo4jTemplate.java:597) at org.springframework.data.neo4j.core.Neo4jTemplate.processRelations(Neo4jTemplate.java:588) at org.springframework.data.neo4j.core.Neo4jTemplate.saveImpl(Neo4jTemplate.java:352) at org.springframework.data.neo4j.core.Neo4jTemplate.save(Neo4jTemplate.java:289) at org.springframework.data.neo4j.repository.support.SimpleNeo4jRepository.save(SimpleNeo4jRepository.java:117)
I'll add a unit test later.

@michael-simons
Copy link
Collaborator

Thanks @VladoKuruc I'll take care of the 2nd issue: #2236

meistermeier added a commit that referenced this issue Apr 19, 2021
@meistermeier meistermeier added this to the 6.1.1 (2021.0.1) milestone Apr 19, 2021
meistermeier added a commit that referenced this issue Apr 19, 2021
Fixes the problem that certain operations did not take the database
selection into consideration when executing queries.

Closes #2234
@meistermeier
Copy link
Collaborator

Thanks for your valuable feedback.

@michael-simons michael-simons added type: bug A general bug and removed bug labels Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants