Announcement Announcement Module
No announcement yet.
[Spring Data Graph] Precisions about Detached Entities and SDG under the hood Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Spring Data Graph] Precisions about Detached Entities and SDG under the hood

    I'm currently testing some of Spring Data Graph features, and I have a few questions about some usages.

    Could someone explain to me how the following example works:

    I run the following unit test:
    	public void testUpdatingEntitiesNotInTransaction(){
    		Movie m = new Movie();
    		Long id = m.getNodeId();
    		Movie retrievedMovie = movieRepository.findOne(id);
    		assertEquals("Leon", retrievedMovie.getTitle());
    And the assertion at the end fails, as retrievedMovie.getTitle() equals "Babel" and not "Leon".
    This point is not really clear in the documentation :
    Does this occurs because of some cache? If so, is it the Neo4j cache? And what is exactly its scope : thread, session, ...?
    Or is any call to getters triggering an access to the database because of AspectJ?

    Anyway, unless I misundestood something, it's a bit confusing. Especially when used to APIs like Hibernate, which don't make any refresh of retrieved entities once we are outside of a transaction.

    When I read this in documentation, I don't expect that any persist operation affect other retrieved entities :
    Changing an attached entity inside a transaction will immediately write through the changes to the datastore. Whenever an entity is changed outside of a transaction it becomes detached. The changes are stored in the entity itself until the next call to persist().

    All entities returned by library functions are initially in an attached state. Just as with any other entity, changing them outside of a transaction detaches them, and they must be reattached with persist() for the data to be saved.
    Maybe I have to precise some points :
    • I'm using Embedded database, with beforeTest cleaning
    • I don't use any transaction in this test.

  • #2
    I am having a similar problem. In my understanding calling setProperty() in the code below should put obj in a detached state, but instead the value of field property gets persisted in the DB.

    void method(){
        obj = getDbObject(objectId); //the method below
        obj.setProperty(value); // value gets persisted in the DB 
    public getDbObject(Long id){
        return dbObjectRepository.findOne(id);
    Am I doing something wrong?

    Could you assist me with this problem?
    How did you get around your problem?