spring-boot Entities and Repositories


Example

A simple entity: Using Lombok @Getter and @Setter annotations to generate getters and setters for us

@Entity
@Getter @Setter
public class Message {
    
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;
    private String message;

}

I am using UUID based ids and lombok to generate getters and setters.

A simple repository for the entity above:

@Transactional
public interface MessageRepository extends CrudRepository<Message, String> {
}

More on respositories: spring data docs

Make sure entities reside in a package that is mapped in em.setPackagesToScan (defined in LocalContainerEntityManagerFactoryBean bean) and repositories in a package mapped in basePackages (defined in @EnableJpaRepositories annotation)