| Ko

JPA dirty checking

Load an entity, call a setter, end the transaction, and the row in the database changes. No save(), no update(). The mechanism behind that automatic UPDATE is dirty checking. The core of it is how Hibernate knows which fields changed and what it compares against. The snapshot The baseline for the comparison is the snapshot. The moment an entity enters the persistence context, Hibernate copies all of its field values and stores them separately. That copy is the initial state that matches the database. Internally it’s keyed by the entity identifier, with an Object array holding each field value in order as the value. ...

June 8, 2024 · 5 min · 967 words · In-Jun

Spring interceptors

What sets an interceptor apart from a filter is position. An interceptor runs inside the DispatcherServlet, after handler mapping has decided which controller handles the request. So an interceptor already knows which handler is about to run. It intercepts that execution at three points (before the controller, after the controller, after view rendering), and at the first point it can block the request entirely. The three hooks HandlerInterceptor provides three methods, each intercepting a different moment. ...

June 4, 2024 · 4 min · 831 words · In-Jun

Servlet filters

A filter is the first thing to touch a request. There’s no DispatcherServlet, no controller, no Spring bean yet, because a filter runs at the servlet container (Tomcat and friends) level. That position defines what a filter is for, and it explains why CORS handling and security token validation live in filters rather than interceptors. Servlet A Java server-side component that processes client HTTP requests and generates responses. It’s a core technology of the Java EE (now Jakarta EE) standard and the foundation of most Java web frameworks. ...

June 4, 2024 · 5 min · 916 words · In-Jun
[email protected]