What is the significance of the @Lock annotation?
The Spring Data JPA @Lock annotation selects the JPA lock mode for a repository query, enabling optimistic or pessimistic locking without EntityManager code.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
The Spring Data JPA @Lock annotation selects the JPA lock mode for a repository query, enabling optimistic or pessimistic locking without EntityManager code.
Use JPA @Version to detect lost updates, test the conflict, return HTTP 409 and expose the version through ETag and If-Match headers.
@SequenceGenerator defines the database sequence JPA uses for primary keys. Learn its attributes, allocationSize and how it compares with IDENTITY.
Use @SequenceGenerator and GenerationType.SEQUENCE to take JPA primary keys from a database sequence, with allocationSize and migration advice.
@TableGenerator generates primary keys from a counter table, which works on any database. See its attributes, a working example and the performance trade-offs.
Use @Transient or the transient keyword to keep a field out of the database, and see why lazy fetching and read-only columns are different things.
@Transient keeps a field out of the JPA mapping so it is never saved or loaded. Use it for calculated values and temporary state.
Use @Embeddable and @Embedded to map value objects like addresses into an entity's table. Covers overrides, composite keys and queries.
@Embeddable defines a reusable value type stored in its owner's table. See examples with @Embedded, attribute overrides, records and composite keys.
Use FetchType.EAGER, JOIN FETCH or an entity graph to load associations together with an entity, and avoid the N+1 and over-fetching traps.
@EntityGraph in Spring Data JPA declares which associations a repository method loads in one query, which removes N+1 selects without making mappings eager.
Paginate native SQL in Spring Data JPA with Pageable and an explicit countQuery, handle sorting safely and use projections.
@NativeQuery is a Spring Data JPA shorthand for @Query(nativeQuery = true). See examples, JPA alternatives and when native SQL is the right choice.
Run database-specific SQL from JPA using EntityManager, named native queries or Spring Data @Query, with safe parameters, paging and projections.
@Column maps a JPA entity field to a database column and controls name, length, nullability, precision and insert or update behaviour. See clear examples.
Use @Table to control the table name and schema an entity maps to, plus constraints, indexes, a global default schema and reserved-word handling.
The JPA @Table annotation controls the table an entity maps to: its name, schema, constraints and indexes. Learn its attributes and its limits.
Cut SQL statements per request in JPA: fix N+1 with fetch joins, entity graphs and @BatchSize, use projections, and batch writes.
@BatchSize makes Hibernate load several lazy collections or entity proxies in one query. See how it fixes N+1 selects and how to configure it.
Learn how to define Apache Camel routes in a Spring Boot app with RouteBuilder beans, the REST DSL, Spring bean calls, routing rules and error handling.