WorksheetsDependency Injection and JPA Entities Worksheet
Total questions: 122
Worksheet time: 1hrs 1mins
Two beans match an injection point. Result?
List injected
NoUniqueBeanDefinitionException
Null
First one injected
Why prefer Constructor Injection for required deps?
Immutability and ensures object is fully valid after construction
Optionality
Legacy
Speed
@ManyToOne default fetch?
Lazy
Eager
Delayed
Manual
@OneToMany default fetch?
Eager
None
Direct
Lazy
Detached entity means?
Locked
Deleted
No longer tracked by EntityManager (Session closed)
New
Entity lifecycle state 'Managed' means?
Deleted
Saved to disk
Attached to Persistence Context
Garbage collected
Exception when accessing lazy collection outside Transaction?
Timeout
NullPointer
SQLException
LazyInitializationException
Field to be ignored by JPA?
@Transient
@Ignore
@Skip
@Temp
IDENTITY ID generation relies on?
Random
Database features (Auto Increment)
Java UUID
Hibernate
JOIN FETCH uses which loading strategy logically?
Async
Eager
Lazy
Delayed
JPQL queries target?
Files
Tables and Columns
XML
Entities and Attributes
Loading children one by one leads to?
N+1 Select Problem
Fast UI
StackOverflow
Deadlock
MappedSuperclass allows?
Table creation
Polymorphic queries
Interfaces
Inheriting fields without a separate table
Mapping Java objects to tables is called?
SQL
JPA
ORM (Object Relational Mapping)
JDBC
Required annotation for JPA class?
@Row
@Model
@Domain
@Entity
Storing Enums as text?
@Text
@Enum
@Varchar
@Enumerated(EnumType.STRING)
Unique identifier definition?
@Id
@UUID
@Primary
@Key
Updating managed entity fields requires?
Calling save()
Calling commit()
Calling update()
Nothing (Automatic Dirty Checking)
Why not use Ordinal for Enums?
Not supported
Takes space
Too slow
Fragile if enum order changes
Annotation for DELETE/UPDATE queries?
@Modifying
@Edit
@Change
@Write
Execute raw SQL query?
EntityManager
RunSQL
jdbcTemplate
@Query(nativeQuery = true)
Interface based projection?
DTO class
Object array
Interface with getter methods matching columns
Map
Main benefit of Spring Data JPA?
Better SQL
Faster DB
New language
Reduction of boilerplate DAO code
Marker interface for Repositories?
Repository
Dao
Service
Component
Pagination interface?
Slice
List
Set
Pageable
Preventing lost updates?
Backups
Optimistic Locking (@Version)
Locking
Pessimism
Query keyword for inequality?
Bad
NotEqual
Not
Diff
Return type when result might be missing?
Void
Null
User
Optional
Slice vs Page?
Slice is slower
Slice doesn't count total (Cheaper), Page counts total
Same
Page is deprecated
Sorting parameter?
Change
Order
By
Sort
To write custom HQL/JPQL?
@SQL
@Custom
@Query
@Script
Who implements the interface at runtime?
Compiler
Spring (via JDK Proxy)
You
Database
countByLastName(String name) is example of?
Derived Query Method
Native SQL
Error
Magic
count() returns?
double
int
long
boolean
exists... methods return?
Boolean
String
Int
Long
Binding user.first-name to user.firstName ?
Error
Relaxed Binding
Impossible
Manual
Build once, run anywhere implies?
Recompiling
Magic
Configuration is separated from Code
Java is slow
Conditional Bean creation?
@Profile
@Check
@When
@If
Default profile name?
dev
main
prod
default
Env variables are suitable for?
Logs
Secrets and Container-specific config
Images
Code
Externalized configuration mantra?
Hide it
Store config in environment
Email it
Hardcode it
Inject specific key?
@Get
@Key
@Prop
@Value
Loading external property file?
@Load
@File
@PropertySource
@Import
Order of precedence Highest?
Command Line Arguments
File
Internal
Env var
Profile specific file naming?
application-profile.properties
application-{profile}.properties
profile-application.properties
application.properties
Difficulty: MEDIUM. PropertySource refers to?
A map of key-values (e.g. system properties)
Real estate
A bean
Variables
Difficulty: MEDIUM. Set server port to 9090?
http=9090
port=9090
host=9090
server.port=9090
Difficulty: MEDIUM. Setting active profile property?
spring.profiles.active
profile
active
mode
Difficulty: MEDIUM. Spring Cloud Config uses?
Local disk
Git (typically) to serve config
FTP
Dropbox
Difficulty: MEDIUM. Standard config file format?
C#
Properties or YAML
Main
HTML
Difficulty: MEDIUM. Type-safe simple configuration?
@Value
@Type
@ConfigurationProperties
@Bean
Difficulty: HARD. YAML advantage?
Encrypted
Binary
Flat
Hierarchical structure
Difficulty: MEDIUM. Calling @Transactional method from within same class?
No proxy interception (Annotation ignored)
Errors
Works
Explodes
Difficulty: MEDIUM. Controller should ideally contain?
Complex logic
SQL
HTML
Only Routing and Validation logic
Difficulty: MEDIUM. DTO is used to?
Save data
Transfer data between processes/layers
Encrypt
Connect DB
Difficulty: EASY. Default rollback rule?
IOExceptions
RuntimeExceptions and Errors
Any Exception
None
Difficulty: EASY. Dirty Read means seeing?
Uncommitted data from another transaction
Deleted data
(MEDIUM) Do Checked Exceptions rollback automatically?
Yes
Always
No
On Sundays
(MEDIUM) Force rollback for Exception?
rollback=true
stop()
failed=true
rollbackFor=Exception.class
(MEDIUM) Highest isolation level?
Read Committed
Repeatable Read
Serializable
Read Uncommitted
(EASY) Idempotent operation means?
Safe to retry multiple times
Random result
Slow
Changes every time
(MEDIUM) Manual mapping leads to?
Speed
Promotion
Fun
Boilerplate and errors
(MEDIUM) Method visibility for @Transactional?
Package
Public
Private
Protected
(MEDIUM) Primary purpose of Transaction?
Security
Logging
Speed
Data Integrity (All or Nothing)
(MEDIUM) REQUIRED propagation?
News
Reuses existing or creates new
Ignores
Fails
(MEDIUM) REQUIRES_NEW behavior?
Merges
Suspends outer, runs independent inner
Fails
Nothing
(MEDIUM) Rich Domain Model vs Anemic?
Anemic has logic
Rich contains business rules, Anemic is data-only
Same
Rich is empty
(MEDIUM) Service layer encapsulates?
Business Logic
UI
Networking
SQL
(MEDIUM) Stateless service allows?
Sessions
Memory usage
Horizontal Scaling
Complexity
@JsonProperty used for?
Database map
Null check
Mapping JSON key name (e.g. 'first_name' → firstName)
Hiding field
Binding body to DTO requires?
@Header
@RequestBody
@Path
@Param
Centralized Error Logic?
Main method
@ControllerAdvice
Each method
Filter
Customizing Headers in response?
Return ResponseEntity
Return String
Return Map
Return void
HTTP 200 OK vs 204 No Content?
200 is fast
204 is verification
204 is error
200 has body, 204 has no body (success for delete/void)
HTTP 404 means?
Not Found
Unauthorized
Bad Request
Server Error
Jackson's role?
Validation
Security
Logging
JSON Serialization/Deserialization
Method for updating resource partially?
PATCH
PUT
POST
GET
REST is independent of?
URI
HTTP
Platform/Language
Resources
Reading '/items/5'?
@Body
@Get
@Query
@PathVariable("id")
Reading '?sort=asc'?
@Header
@RequestParam
@Path
@Body
Returning objects from controller is automatically converted to?
JSON (if Jackson on classpath)
XML
Binary
String
Richardson Maturity Model Level 3?
HATEOAS (Hypermedia)
Tunneling
Verbs
XML
Safe methods (don't modify state) include?
GET and HEAD
DELETE
PUT
POST
What does being 'Stateless' mean in REST?
Server does not store client context between requests
Server is down
No Memory
No DB
Building a URL?
~{...}
@{/path}
# {...}
${...}
Can you open Thymeleaf file in Chrome directly?
No
Yes (Nature Templating)
Only if compiled
Only in IE
Conditional display?
th:display
th:if
th:hide
th:show
Decorator pattern in Thymeleaf?
Via JS
Layout Dialect
Impossible
Via CSS
Default suffix for templates?
.txt
.html
.jsp
.th
Expression [[...]] is?
Comments
Hidden
Arrays
Inlining (output text directly)
Form binding object?
th:form
th:bind
th:data
th:object
Is Thymeleaf interpreted?
Yes (mostly)
No
Only in dev
It is binary
Iterating a list?
th:list
th:loop
th:repeat
th:each
Replacing text content only?
th:text
th:val
th:html
th:attr
Reusing header/footer?
th:fragment
th:replace
th:each
th:text
Selecting a variable?
@{x}
*{x}
#{x}
${x}
Sending data to View?
Request.set
Globals
Model.addAttribute()
Cookies
Server-Side Rendering (SSR) sends what to browser?
XML
JSON only
Fully rendered HTML
Java code
Thymeleaf works as?
Compiler
Database
Server-side template engine
Client framework
Accessing current user in code?
SecurityContextHolder.getContext()
System.in
Session.get
Thread.current
Allowing cross-domain AJAX?
CORS (Cross Origin Resource Sharing)
Firewall
Proxy
VPN
AntMatchers are used for?
Insects
Regex
Beans
URL path matching config
Authorization check for role 'ADMIN'?
isUser()
checkAdmin()
hasRole('ADMIN')
allow()
Default behavior for unauthenticated request?
500
Allow
404
Redirect to Login / 401
Filter order matters?
Yes, strictly ordered chain
Random
Sometimes
No
FormLogin configures?
Username/Password form auth
OAuth
Basic Auth
LDAP
Method level protection annotation?
@Lock
@Secure
@PreAuthorize
@Guard
Preventing form forgery?
XSS
SQLi
CSRF Token
CORS
Service to load user by username?
UserService
LoginService
AuthService
UserDetailsService
Spring Security is implemented via?
Servlet Filters (FilterChain)
Agents
Reflect
AOP
Storage for user details?
String
UserDetails (Interface)
List
Map
Storing passwords safely?
MD5
Cleartext
Adaptive Hashing (BCrypt/SCrypt)
Rot13
Who is the 'Principal'?
Database
Admin
Currently logged in user
Server
@Email matches?
IP address
Domains
Nothing
Email format structure
@Min(18) requires?
String length 18
Year 2018
Number value >= 18
Array size 18
@Past validates?
Timezone
Date is in the past
Numbers
History
Bean Validation standard is?
JTA
JDBC
JSR-380 (Jakarta Validation)
JPA
Checking boolean is true?
@True
@Check
@AssertTrue
@Yes
Checking if String has text?
@HasChars
@Text
@NotNull
@NotBlank
Creating custom constraint?
New Method
New Interface
Annotation + ConstraintValidator implementation
New Class
Groups allow?
Batching
Context-specific validation checks
Sorting
Teams
Message interpolation handles?
Speed
Routing
User-friendly error messages (i18n)
Math
