-
Notifications
You must be signed in to change notification settings - Fork 617
Relations are not saved correctly [DATAGRAPH-1017] #1578
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
Comments
František Hartman commented Thank you for reporting this. The issue in the test is that it executes every operation on the repository in a separate transaction (hence separate session) - due to EnableNeo4jRepositories#enableDefaultTransactions is true by default. Annotated with The actual issue here is that it manages to autowire the Session - it should fail with something like "no active transaction for current thread" |
niels commented Hi thank you for analyzing the issue. I don't understand your comment. |
František Hartman commented Yes, I mean the SO-referenced test SocietyApplicationTests. The OGM one uses one session only - that's why the delete works - you need to perform the load and delete with the same Session - that's how OGM recognizes that a relationship was removed from a collection and should be deleted. The SDN test case uses default transaction management, so a new session and transaction for each operation (OGM Session is bound a transaction in SDN). The testCrudOperationsWithRelations test fails because for Collection the default is HashSet and you use id in your equals and hash code (you should depend on other fields that graph id when using hash based collections) - this is my guess, I haven't verified this, but quickly changing to List fixes the test |
niels commented Hi Frantisek, thanks for explaination. Now I understand the behavior (the typical session issues like in hibernate). I added the information at SO. However I still can't change relationship with the Regards |
The correct solution is stated on Stack Overflow. For Spring Data Rest to work correctly, an Open Session in View interceptor is needed. The most easiest way to do this is a config like this import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
import org.springframework.web.servlet.handler.MappedInterceptor;
@Configuration
public class MyWebAppConfigurationForSpringDataRest {
@Bean // <.>
public OpenSessionInViewInterceptor openSessionInViewInterceptor() {
return new OpenSessionInViewInterceptor();
}
@Bean // <.>
public MappedInterceptor mappedOSIVInterceptor(OpenSessionInViewInterceptor openSessionInViewInterceptor) {
return new MappedInterceptor(new String[] { "/**" }, openSessionInViewInterceptor);
}
} which is taken straight from the enhanced section of the 5.1.x, 5.2.x and 5.3.x FAQ after the following commits. |
…-in-view interceptor. This closes #1578.
…-in-view interceptor. This closes #1578.
…-in-view interceptor. This closes #1578.
niels opened DATAGRAPH-1017 and commented
Relationsships are not handled correctly. I tried to create an example where I show the behavior of https://stackoverflow.com/questions/44907670/spring-data-rest-with-neo4j-how-to-remove-relationship. Unfortunately I make the experience that the relations wasn't save correctly.
I didn't find a correct example.
I make a branch based von the 4.2.x branch and extended the test-class Neo4jRepositoryIT. So you can see the problem directly
Affects: 4.2.6 (Ingalls SR6)
Reference URL: https://github.com/opensource21/spring-data-neo4j/tree/4.2.x-relationBug
Issue Links:
("is duplicated by")
("is duplicated by")
The text was updated successfully, but these errors were encountered: