Database Reference
In-Depth Information
That said, let's take a look at the next listing and dig a little deeper into what's happening
with the loading and saving methods, as well as everything in between.
Listing 9.10. Loading and saving
The
findOne
method available via the
CRUDRepository
interface is classified as
one of the load methods. When this line of code executes, SDN will do three things:
• Create a new
User
object.
• Load the underlying
Node
class into memory.
• For each property and certain relationships (those without
@Fetch
annotations,
which we'll come to shortly), copy the data out of the graph and into the POJO
classes properties.
ThenexttimeSDNinteractswiththeunderlyingnodeiswhenanexplicitsaveiscalled
. Nothing between these points ever results in a call to the underlying database; everything
is done on the domain objects. Technically, entities that have just been created or modified
but not yet saved are said to be in a
detached
state.
Transitive persistence
The other noteworthy point to make about this code is that when John is saved , Susan
gets saved too. Lucky Susan! So what's special about John? Whenever a save operation is
invoked, SDN will look at the object to be persisted (John, in this case) and detect what's