Spring Data Flashcards
What built-in class does Spring provide that implements Pageable?
PageRequest
Spring Data
What is the signature for a “derived query method”?
[Subject Keyword][(Optional Description]By[Predicate]
[Subject Keyword]
could be:
1. Find 2. Exists 3. Count 4. Delete
[Optional Description]
could be:
1. First<number> 2. Distinct
[Predicate]
is composed of:
1. Class Property 2. Logical keywords
What annotation can be used on the main configuration class to scan for domain objects defined outside of its directory or sub-directories?
@EntityScan(basePackages=String[])
What is Spring Data?
Spring Data is a framework for building data access applications
What is a repository?
A repository is a data access object. It’s used to interface with a database
What is a datasource/connection string?
A datasource is all the information an application needs to connect to a database
How can you make a repository method implement a native query?
Annotate the query method with @Query
What annotation on the main configuration class can be used to scan for repositories outside of its package?
@EnableMongoRepositories(basePackages=String[])
What are the 2 steps to implement custom repositories?
- Define a custom interface and implementation
- Define a normal repository interface that extends both a Spring repository and the custom interface
What is the relationship between @EnableAutoConfiguration and @Document?
@Document will be scanned for by the configuration class that is annotated with @EnableAutoConfiguration (@SpringBootApplication)
What is the difference between Page
and Slice
?
A Page knows about the total number of elements and pages available. It does so by the infrastructure triggering a count query to calculate the overall number. As this might be expensive (depending on the store used), you can instead return a Slice. A Slice knows only about whether a next Slice is available, which might be sufficient when walking through a larger result set
Do “query derived methods” support the use of parameters that are mapped to @DBRef fields in the domain class?
No
Can a “derived query method” be used to update a document?
Yes. For example:
@Update("{ '$set' : { 'password' : ?1 } }") void findAndSetPasswordByEmail(String email, String password);
True or False
“Derived query methods” annotated with @Update
must return either void or a numeric type
True
What is the difference between @DBRef
and @DocumentReference
?