
Estou publicando a continuação da coleção de perguntas e respostas da entrevista para o desenvolvedor Backend-Java. Na primeira parte, percorremos Java e Spring. E neste, vamos falar sobre Hibernate, bancos de dados, padrões e práticas de desenvolvimento, uma biblioteca popular, suporte e manutenção de nossos aplicativos e também olhar para folhas de dicas alternativas e resumir.
Um repositório GitHub com uma folha de dicas completa está aqui , e Habr ainda é um bolo.
Questões
Hibernar
3 níveis de cache:
- Cache de primeiro nível. Ativado por padrão.
- Cache de segundo nível. Desativado por padrão.
- Cache de consulta. Desativado por padrão.
Mais detalhes:
- Artigo sobre Habré
- Baeldung
- First Level Cache Second Level Cache
Hibernate Vlad Mihalcea:
- High-Performance Java Persistence: 2, 16 — Caching
- How does Hibernate Query Cache work
- How does Hibernate Collection Cache work
- How does Hibernate store second-level cache entries
- How does Hibernate NONSTRICT_READ_WRITE CacheConcurrencyStrategy work
- How does Hibernate TRANSACTIONAL CacheConcurrencyStrategy work
- How does Hibernate READ_ONLY CacheConcurrencyStrategy work
- How does Hibernate READ_WRITE CacheConcurrencyStrategy work
- Eager Loading — , . (
@OneToOne
,@ManyToOne
,@OneToMany
,@ManyToMany
)fetch = FetchType.EAGER
.@OneToOne
@ManyToOne
. - Lazy Loading — , . , (
@OneToOne
,@ManyToOne
,@OneToMany
,@ManyToMany
)fetch = FetchType.LAZY
.@OneToMany
,@ManyToMany
. proxy-, . LAZY- Hibernate, LazyInitializationException.
"N+1" .
Vlad Mihalcea: , LazyInitializationException .
N+1 Hibernate, .
N+1 , N , . N . slow query log
, , .
plain sql (jdbc, JOOQ), ( ) . , . " !?". - , - . ? JOIN
. .
Hibernate. "N+1", . .
, FetchType.EAGER
. N+1. @ManyToOne
. JPQL JOIN FETCH
. , FetchType.LAZY
.
FetchType.LAZY
, , N+1. , . — . JOIN FETCH
.
JOIN FETCH
, bonjour. @OneToMany
FetchMode.SUBSELECT
— 2 , . .. .
— . @BatchSize
.
:
- JPA EntityGraph
- Hibernate FetchProfile
N+1, db-util Vlad Mihalcea. .
JOOQ N+1 , 17- (01:16:36) +. JOOQ.
:
- Vlad Mihalcea:
- Hibernate —
- DOU JPA Hibernate
- JPoint " Hibernate "
:
— , . .
Hibernate, @Embeddable
. , Serializable
equals
hashcode
.
, , @EmbeddedId
.
Vlad Mihalcea Hibernate.
4 JPA (Hibernate):
- MappedSuperclass — . . @MappedSuperClass,
@Entity
. , , @AttributeOverride . . . - Single table — . , -.
@Entity
-@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "YOUR_DISCRIMINATOR_COLUMN_NAME")
(DTYPE
VARCHAR
).@DiscriminatorValue("ThisChildName")
, - . , @DiscriminatorFormula,CASE...WHEN
— JPA, Hibernate. . . —NULL
. - Joined table — , . , ( ) .
@Entity
-@Inheritance(strategy = InheritanceType.JOINED)
.JOIN
,CASE...WHEN
,_clazz
, (0 (), 1, 2 ..) Hibernate . - Table per class —
MappedSuperclass
, . . JPA 2.2 ( 2.12) , Hibernate , .@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
. (@Id
) .@AttributeOverride
— .UNION
. , Hibernate_clazz
, (1, 2 ..).NULL AS some_field
. .
:
- : ,
- Vlad Mahalcea: MappedSuperclass
, JavaDoc :
- JPA
- Hibernate
JPA 2.2. pdf.
Postgresql. Postgres Pro:
WHERE HAVING , WHERE , ( , ), HAVING . , WHERE ; . HAVING, , . ( , HAVING, , . WHERE.)
:
- How does a relational database work
- How does a relational database execute SQL statements and prepared statements
- How Database Internally Works
- Let's Build a Simple Database
- Database internals
- A — (Atomicity). , .
- C — (Consistency). .
- I — (Isolation). .
- D — (Durability). (, - ).
:
Read uncommitted
( ). (, ).Read committed
( ). . «» ( , , ).Repeatable read
( ). (, ).Serializable
(). , , — (, ).
:
- MSSQL: , ,
- PostgreSQL. Postgres Professional, egorov PostgreSQL (, , ..). Postgres Professional .
- MySQL: ,
— , . . /. .
:
- B-Tree
- HASH-
- Bitmap
- Spatial grid
- Quadtree
- R-Tree
- .
. .
, :
- — , . B-.
- — , . .
: - — . ID , ; ID ; ; . .
- — , . , .
:
- Oracle, MySQL, PostgreSQL, MS SQL
- PostgreSQL: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- «» MySQL (InnoDB)
- « » Postgres
- , , ?
- :
- : ,
- Database Indexes Explained
- Bitmap- B*tree-: ?
- MySQL
- PostgreSQL Java-
- 14 SQL Server,
- ,
- PostgreSQL
- Anatomy of an SQL Index
- SQL Indexing and Tuning e-Book
- Deep dive into Hash indexes for In-Memory OLTP tables
- Indexing based on Hashing
- SQL Server Indexes Interview Questions and Answers
- Top 25 SQL interview questions and answers about indexes
- An in-depth look at Database Indexin
(lock) — .
— , . , . . , , .
:
- shared (read) — , . , , .
- exclusive (write) — , . . , .
— , ( VERSION
0
). , , . — (, ) , .
, , . , .
Vlad Mihalcea:
- A beginner’s guide to Java Persistence locking
- A beginner’s guide to database locking and the lost update phenomena
- How do LockModeType.PESSIMISTIC_READ and LockModeType.PESSIMISTIC_WRITE work in JPA and Hibernate
- How does LockModeType.PESSIMISTIC_FORCE_INCREMENT work in JPA and Hibernate
- How does LockModeType.OPTIMISTIC work in JPA and Hibernate
- How does LockModeType.OPTIMISTIC_FORCE_INCREMENT work in JPA and Hibernate
- How to prevent OptimisticLockException with Hibernate versionless optimistic locking
- How does database pessimistic locking interact with INSERT, UPDATE, and DELETE SQL statements
- How does MVCC (Multi-Version Concurrency Control) work
- How does the 2PL (Two-Phase Locking) algorithm work
- How to prevent lost updates in long conversations
:
- .
- Version JPA
- Hibernate – V.
- PostgreSQL: 1.
- PostgreSQL: 2.
- PostgreSQL: 3.
- PostgreSQL: 4.
:
- Pessimistic Locking in JPA
- Optimistic Locking in JPA
- Enabling Transaction Locks in Spring Data JPA
- Deadlock
- Enum LockModeType
- Postgresql
- PostgreSQL Concurrency with MVCC
- Locking Hibernate
- Optimistic locking JOOQ
- Optimistically Locking Your Spring Boot Web Services
- Optimistic and pessimistic locking with SQL
, ,
, . . , . , , , .
- S — (The Single Responsibility Principle). .
- O — / (The Open Closed Principle). , .
- L — (The Liskov Substitution Principle). . , .
- I — (The Interface Segregation Principle). , .
- D — (The Dependency Inversion Principle). , .
, , " " , . ? 3 " ". , , . , :)
, -. , . SOLID - . - SOLID .
, , , . Baeldung.
GoF. , , — refactoring.guru. , (, , , ), , . . - .
Coupling () — . .
Cohesion () — . .
.
. , :
- : . , .
coupling cohesion GRASP. : .
(scale cube, The Art of Scalability) : sharding, mirrorring microservices.
- Sharding (data partioning) — .
- Mirroring (horizontal duplication) — .
- Microservices — , -.
:

:
- .
- microservices.io.
- wiki pros cons.
- SCALING APPLICATIONS: THE SCALE CUBE.
- .
- .
- Microservice Patterns and Best Practices Microservices Patterns ( ).
-, . . - "".
— Microservice Patterns and Best Practices. Medium .
microservices.io : . — . .
. — Enterprise Integration Patterns .
CAP — , , :
- Consistency () — — . — - , , .
- Availability () — , .
- Partition tolerance ( ) — , ( ) - ( ).
MongoDB, (), — CP, … , . .
.
:
- : , , , ,
- Visual Guide to NoSQL Systems CAP
- The CAP FAQ
- bigdataschool
- MongoDB stackoverflow
- CAP Theorem IBM
- CAP Theorem and Distributed Database Management Systems
- What is the CAP Theorem? medium
- (SOA) — , , . SOA — , . SOA - .
:
- - ( , -, , ..);
- ;
- " " .
-
(MSA) — SOA, , , (). MSA , , .
: - (Unix way — );
- ;
- ( );
- " " .
, MSA , SOA — . . — , . MSA SOA . , .
:
- SOA
- , SOA API ibm SOA MSA
- Monolith vs SOA vs MSA medium
- Microservices vs SOA DZone
- MSA SOA
- SOA MSA
:
- () -> , , , , , ( )
- ->
- ,
:
- () — (/, ..)
- ,
:
- . : , , , , , 2018
- Wikipedia
- Microservices — Not A Free Lunch!
- —
- What are microservices?
- To go or not to go micro: the pros and cons of microservices
- Microservices in a Nutshell. Pros and Cons
:
- HeadHunter
- :
- ,
(composition) — " " (HAS-A Relationship), .
(aggregation) — " " (HAS-A Relationship), , .
:
- vs vs
- , ,
(Test Double) — ,
:
- Dummy — , , . : , null
- Fake — , , production-. : in-memory (fake database)
- Stub — (system under test — SUT)
- Spy — Stub, , , ..
- Mock — ,
Mock , — .
:
- Mock vs Stub
- Mocks Aren't Stubs
- Test Double
- Test Stub
- Test Spy
- Mock Object
- Fake Object
- Interaction Based Testing Spock Framework
- Mockito
- Mockito Mock vs. Spy in Spring Boot Tests
- Tag: Mockito Bealdung
:
“” , .
:
- . :
- — , , . (Generic).
- (inclusive) — , . .
- ( ad-hoc) — () . :
- (overloading) , ().
- — , , .
Java .
:
- Java Challengers #3:
- JVM
- Java
- Java Virtual Machine Specification: Invoking Methods, invokevirtual, Linking
- Java Language Specification: Inheritance, Overriding, and Hiding, Conversions and Contexts, Type Inference
REST – , web-.
REST, :
- URI
- — JSON, XML
- — HTTP. — , . .
- HTTP . GET: ; POST: ; PUT: ; DELETE: . — PUT vs PATCH vs POST.
- HTTP . HTTP- .
- HATEOAS , REST,
, , HTTP- URI, API RESTful. , . , , REST — , . — .
REST- :
- - (Client–server)
- (Stateless) —
- (Cacheable) —
- (Uniform interface) — , , "" , HATEOAS
- (Layered system) — , .
- ( ) (Code on demand (optional)) —
SOAP — .
SOAP:
- — XML (SOAP-XML — Envelope, Header, Body, Fault)
- SOAP- WSDL( XML)
- SOAP — (TCP, UDP, HTTP, SMTP, FTP ..)
- HTTP, GET POST
, web-, .
-:
- REST — , REST vs SOAP, Contract First, Code First, HATEOAS, Java Spring
- REST vs SOAP. 1. REST vs SOAP. 2. ?
- . ( !)
- REST API Best Practices
- RESTful
- RESTful API
- REST-like API
- web API
- RESTful API – ( 1) RESTful API – ( 2)
- : REST
- 7 REST API
- JAX-WS XSD Restrictions
- REST API Java
- Spring Boot: REST API Java
- RESTful Kotlin Spring boot
- SOAP- Java Apache CXF Spring
- SOAP Web- Spring-WS
-:
- REST — SOAP
- REST 200
- REST API
- RESTful API —
: - REST GraphQL
- REST? JSON-RPC
: - A Brief Introduction to REST
- REST CookBook
- RESTful Web APIs
- Introduction to Spring Data REST
- What is REST
- Building REST services with Spring
- SOAP Web-
- SOAP
, ! !
Lombok — , , , , . Lombok .
? ? , . — .
— : " - ?". . , -, .
, , Lombok — IDEA. , . ! 2020.3 Lombok- IDEA.
Lombok , . , Hibernate ( ) Lombok entity-. @EqualsAndHashCode, @ToString @Data, equals
, hashCode
toString
, entities. entities .
, , "+" 7-8 — . asm0dey Lombok Lombok . : " , , @SneakyThrows ?" ( ), " @Data. equals ?", " @EqualsAndHashCode StackOverflowException ?".
Lombok — — , . — . Lombok — Lombok, . - , , .
P.S. Lombok onX — (@__
Java 7) . , Spring-.
:
- Project Lombok
- Who Needs Lombok Anyhow
- Be Careful With Lombok
- Don’t use Lombok
- Lombok & Hibernate: How to Avoid Common Pitfalls
- Error handling with @Transactional and @SneakyThrows
- Lombok, sources.jar
- Some Dangers of Using Lombok
, (), .
OpenNET — , .
MSDN.
— .
.
:
- Apache JMeter — , opensource, HTTP, HTTPS, FTP, LDAP, SOAP, TCP, shell-. , java-based , JDBC, Message-oriented middleware (MOM) JMS Java Objects.
- LoadRunner — . , Enterprise.
- LoadNinja — , - . , .
- WebLOAD — . , , , CI/CD.
- LoadUI Pro — SOAP UI, . - , API.
- K6 — opensource , . JavaScript. , , , Kafka, Datadog, InfluxDB, JSON StatsD. CI-.
- . — , — hit-based- HTTP- Phantom jMeter. , , , .
- Gatling — opensource Scala Netty Akka. Scala, Jenkins.
:
- -
- :
- Gatling
- Top 10
- 9
- 10 Apache JMeter
- jMeter —
- Rest API Load testing with Apache JMeter
- Load Testing with Gatling — The Complete Guide
- -
(Virtual Machine — VM) — / , . — , . .. , , . . VM , . backup' VM .
VM .
— / , , .
KVM QEMU, XEN, VMWare Hyper-V.
Docker — , , , .. .
, . , . linux namespaces. cgroups.
, Dockerfile
, () , . , , . .
Docker- CI/CD.
Docker- — Docker-Hub
Docker, .
Docker:
- VM Docker?
- " Docker": 1, 2, 3, 4, 5, 6
- Docker.
- docker- ( docker run runc)
- Docker: AWS
- : Docker .
- docker
- Linux namespaces
- Docker
- Docker
- Docker Y
- Docker , ,
- Docker-
- Docker
- 10 Docker: 1, 2
- Docker:
- Docker:
- containerd Docker
- : containerd "" CNCF
:
- . ?
- . 1.1.
- Hyper-V:
- Hyper-V Windows 10
- QEMU-KVM
- KVM.
- : KVM vs. Xen
- Hyper-V KVM?
, :
- Containers vs. virtual machines
- Play with Docker
- Docker
- The Docker EcoSystem
- Hardware-assisted virtualization
- Full virtualization
- : KVM, Hyper-V VMware?
- KVM
- KVM
- Unix. 1: Kernel-based Virtual Machine (KVM)
- Linux/Cgroups
- : cgroups
- , VM Docker
- containerd
- awesome-compose
- Learn Docker & Containers using Interactive Browser-Based Scenarios
- What Is Docker & Docker Container? A Deep Dive Into Docker!
- Docker for beginners
— - Java- — , URL- URL ..
( -, ( Java EE)):
- — Apache Tomcat. : (TomEE)
- Jetty
- Undertow
— , Java EE ( Jakarta EE).
: - Wildfly
- Apache TomEE
- IBM WebSphere
- Eclipse GlassFish
" , Tomcat" .
-
- Java-backend, Java core (60 )
- Spring:
- Java 1: JPA Hibernate
- JavaSobes telegram
- Awesome-interview-questions/Java
- Java Developer
- Java Developer
- Java
- JBook
- Telegram- Java: fill the gaps
- Telegram- middlejava
- Telegram- Java Developer
- Telegram- microJUG miniJUG
- Telegram- javaswag
- 50 Docker, ,
- — Java-
- Every Programmer Should Know
- : 1, 2, 3
Backend-Java- . , , , " " . , JUG.RU.
, , PR GitHub .
! ! ( ) . , — .
Além disso, memorizar as respostas às perguntas acima não garante um emprego bem-sucedido, um bom trabalho e cabelos sedosos.