Ask all your coding questions @ codequery.io
Java Persistence API
Spring Data JPA provides an abstraction for more easily working with a JPA provider like Hibernate.
The @Id annotation marks a field as the primary key for that particular table. This is a unique identifier for each entry in the table. This annotation is typically used with @GeneratedValue to automatically generate an unique id for each entry in the table.
The @Entity annotation indicates a class represents a relational table in the database. The JPA specification includes any class marked with @Entity in the persistence setup.
FetchType attribute indicates how whether records will be eagerly or lazily loaded from the database. When records are eagerly loaded, JPA returns these objects regardless of whether they are accessed by the client or not. When records are lazily loaded the actual objects are only retrieved when directly accessed. This can save memory and processing when appropriate.
No. CrudRepository is an interface exposed by Spring Data framework for more easily interacting with JPA implementations like Hibernate. While this interface saves a lot of boilerplate code, it isn't part of the JPA specification.
No. Spring Data simply makes it easier to interface with a JPA specification like Hibernate. Spring Data JPA abstracts away a lot of the configuration associated with these implementations but is not an implementation itself.
No. The @Column field allows you to optionally override the name of the column that the entity class field maps to in the database table. It is not required.
mappedBy is an attribute that specifies the owning side of a one to many relationship. For example, if you want to establish a one to many relationship between authors and books you would specify mappedBy="authors" on the Books entity.
This annotation enables the automatic generation of JPA repositories. Any class which implements CrudRepository interface will generate a repository when this annotation is present.
ORM is a mechanism for maintaining the relationship between object oriented data structures and relational tables in a database. Hibernate is an ORM tool that implements the JPA specifications. ORM allows objects (POJOS) to represent database tables and serves as an abstraction for database querying.
Hibernate, TopLink, ORMLite, iBATIS, JPOX
The @Query annotation allows you to define a Spring Data Repository method with custom SQL. Using @Query, you can map Spring Data repository methods to actual SQL statements.
CrudRepository extends REpository interface. JpaRepostitory extends PagingandSortingRepository interface. CrudRepository is for CRUD methods only where batch operations are better handled by extending JpaRepository.
The save() method effectively "upserts" a record. If the record doesn't exist in the database, then persist() is called. If the record does exist, then merge() is called to perform an update.