我正在为Backend-Java开发人员发布面试问题和答案的集合。在第一部分中,我们介绍了Java和Spring。在这一节中,我们将讨论Hibernate,数据库,模式和开发实践,一个流行的库,对我们应用程序的支持和维护,还将介绍替代备忘单并进行总结。
GitHub备有完整备忘单的存储库在这里,而Habr仍然是一块蛋糕。
问题
冬眠
3级缓存:
- 一级缓存。默认启用。
- 二级缓存。默认禁用。
- (Query cache). .
:
- 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" .
N+1 Hibernate, .
N+1 , N , . N . slow query log
, , .
plain sql (jdbc, JOOQ), ( ) . , . " !?". - , - . ? JOIN
. .
, FetchType.EAGER
. N+1. @ManyToOne
. JPQL JOIN FETCH
. , FetchType.LAZY
.
FetchType.LAZY
, , N+1. , . — . JOIN FETCH
.
JOIN FETCH
, bonjour. @OneToMany
FetchMode.SUBSELECT
— 2 , . .. .
— . @BatchSize
.
:
N+1, db-util Vlad Mihalcea. .
JOOQ N+1 , 17- (01:16:36) +. JOOQ.
:
- Vlad Mihalcea:
- Hibernate —
- DOU JPA Hibernate
- JPoint " 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 2.2. pdf.
Postgresql. Postgres Pro:
WHERE HAVING , WHERE , ( , ), HAVING . , WHERE ; . HAVING, , . ( , HAVING, , . WHERE.)
:
- 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-.
- — , . .
: - — . 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
— , . , . . , , .
:
- 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
:
:
- 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
, ,
GoF. , , — refactoring.guru. , (, , , ), , . . - .
(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 ( ).
CAP — , , :
- Consistency () — — . — - , , .
- Availability () — , .
- Partition tolerance ( ) — , ( ) - ( ).
.
:
- : , , , ,
- 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 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
:
(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) — () . :
- 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
-:
, ! !
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-.
:
.
:
- 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.
:
(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
:
, :
- 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
-
- 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 .
! ! ( ) . , — .
此外,记住以上问题的答案并不能保证成功就业,做好工作和头发柔滑。