there are two states attached and detached:
an entity is detached when it is created or when it is changed outside of a
transaction.
Otherwise (when it is freshly loaded, or after persist it is attached).
For detached entities: persist() writes the changed properties and
relationships to the graph. if attached (and inside of a tx) all changes are
written directly.
In your example you just overwrote the title with Babel and persisted that
information to the graph, so the assert should say:
The retrieved movie is attached, it is never detached, so it always refers to
the node in the graph (read-through) (the data is _not_ copied).
> assertEquals("Babel", retrievedMovie.getTitle());
Attached entities read their data directly from the underlying node.
HTH
Michael
The model is different to hibernate, as hibernate has no read-through. We would
have loved not to support detached entities but as they are so common in
web-frameworks we had to.
The best way of working with SDG is to use domain level service methods which
are transactional and do the interaction with the graph. Detached entities
should just be used to (if at all) to persist
user input (form data) from the UI.
Am 23.08.2011 um 10:56 schrieb Michel Domenjoud:
> Hello,
> 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:
>
> @Test
> public void testUpdatingEntitiesNotInTransaction(){
> Movie m = new Movie();
> m.setTitle("Leon");
> m.persist();
> Long id = m.getNodeId();
> Movie retrievedMovie = movieRepository.findOne(id);
> m.setTitle("Babel");
> m.persist();
> 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.
>
>
> Thanks by advance for your help!
> Michel
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user