{"id":27103015,"url":"https://github.com/yoanesber/spring-boot-hibernate-native-query-postgresql","last_synced_at":"2026-05-17T17:36:41.106Z","repository":{"id":285329316,"uuid":"940142757","full_name":"yoanesber/Spring-Boot-Hibernate-Native-Query-PostgreSQL","owner":"yoanesber","description":"This Spring Boot RESTful API manages Netflix Shows with CRUD operations using Spring Data JPA (Hibernate) and PostgreSQL. It leverages Lombok to reduce boilerplate code and uses Native Queries in JPA for complex SQL operations, ensuring better control and performance where JPQL falls short.","archived":false,"fork":false,"pushed_at":"2025-03-31T04:03:24.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T05:19:32.775Z","etag":null,"topics":["hibernate","jpa-hibernate","native","query","spring-boot","sql-query"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yoanesber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-27T17:23:43.000Z","updated_at":"2025-03-31T04:47:39.000Z","dependencies_parsed_at":"2025-03-31T05:19:37.096Z","dependency_job_id":"79ef60dd-178d-46df-8499-1e70261158fe","html_url":"https://github.com/yoanesber/Spring-Boot-Hibernate-Native-Query-PostgreSQL","commit_stats":null,"previous_names":["yoanesber/spring-boot-hibernate-native-query-postgresql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yoanesber/Spring-Boot-Hibernate-Native-Query-PostgreSQL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoanesber%2FSpring-Boot-Hibernate-Native-Query-PostgreSQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoanesber%2FSpring-Boot-Hibernate-Native-Query-PostgreSQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoanesber%2FSpring-Boot-Hibernate-Native-Query-PostgreSQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoanesber%2FSpring-Boot-Hibernate-Native-Query-PostgreSQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoanesber","download_url":"https://codeload.github.com/yoanesber/Spring-Boot-Hibernate-Native-Query-PostgreSQL/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoanesber%2FSpring-Boot-Hibernate-Native-Query-PostgreSQL/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259470939,"owners_count":22862996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hibernate","jpa-hibernate","native","query","spring-boot","sql-query"],"created_at":"2025-04-06T16:38:30.663Z","updated_at":"2026-05-17T17:36:36.083Z","avatar_url":"https://github.com/yoanesber.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Native Query PostgreSQL\n\n## 📖 Overview\nThis project is **a RESTful API** built using **Spring Boot** that manages **Netflix Shows**. The API provides CRUD operations using **Spring Data JPA with Hibernate** as the default JPA provider. The database used is **PostgreSQL**, and the project leverages **Lombok** to reduce boilerplate code.  \n\n**A key aspect** of this project is the use of **Native Query** in JPA Hibernate at the repository layer. Unlike **JPQL (Java Persistence Query Language)**, which is an object-oriented query language, native queries **allow direct execution of SQL queries** on the database. This provides **flexibility** to utilize complex SQL operations, database-specific functions, or optimized queries that **might not be feasible using JPQL**. In this project, the `@Query` annotation with `nativeQuery = true` is used to execute raw SQL queries directly. This ensures greater control over database interactions and can improve performance in specific scenarios where JPQL is not efficient.  \n\n---\n\n## 🤖 Tech Stack\nThe technology used in this project are:\n- `Spring Boot Starter Web` – Building RESTful APIs or web applications\n- `PostgreSQL` – Database for persisting Netflix Shows\n- `Hibernate` – Simplifying database interactions\n- `Lombok` – Reducing boilerplate code\n---\n\n## 🏗️ Project Structure\nThe project is organized into the following package structure:\n```bash\nnative-query-postgresql/\n│── src/main/java/com/yoanesber/spring/hibernate/native_query_postgresql/\n│   ├── 📂controller/            # Exposes REST API endpoints for handling requests and responses\n│   ├── 📂dto/                   # Data Transfer Objects (DTOs) for request/response payloads\n│   ├── 📂entity/                # Entity classes representing database tables\n│   ├── 📂repository/            # JPA repositories for database access\n│   ├── 📂service/               # Business logic layer\n│   │   ├── 📂impl/              # Implementation of services\n```\n---\n\n## ⚙ Environment Configuration\nConfiguration values are stored in `.env.development` and referenced in `application.properties`.  \nExample `.env.development` file content:  \n```properties\n# Application properties\nAPP_PORT=8081\nSPRING_PROFILES_ACTIVE=development\n \n# Database properties\nSPRING_DATASOURCE_PORT=5432\nSPRING_DATASOURCE_USERNAME=your_username\nSPRING_DATASOURCE_PASSWORD=your_password\nSPRING_DATASOURCE_DB=your_db\nSPRING_DATASOURCE_SCHEMA=your_schema\n```\n\nExample `application.properties` file content:  \n```properties\n# Application properties\nspring.application.name=native-query-postgresql\nserver.port=${APP_PORT}\nspring.profiles.active=${SPRING_PROFILES_ACTIVE}\n\n# Database properties\nspring.datasource.url=jdbc:postgresql://localhost:${SPRING_DATASOURCE_PORT}/${SPRING_DATASOURCE_DB}?currentSchema==${SPRING_DATASOURCE_SCHEMA}\nspring.datasource.username=${SPRING_DATASOURCE_USERNAME}\nspring.datasource.password=${SPRING_DATASOURCE_PASSWORD}\n```\n---\n\n## 💾 Database Schema (DDL – PostgreSQL)\nThe following is the database schema for the PostgreSQL database used in this project:  \n```sql\nCREATE SCHEMA your_schema;\n\nCREATE SEQUENCE your_schema.id_netflix_shows_seq\nSTART WITH 1\nINCREMENT BY 1\nNO MINVALUE\nNO MAXVALUE\nCACHE 1;\n\nCREATE TABLE your_schema.netflix_shows (\n\tid int8 NOT NULL DEFAULT nextval('your_schema.id_netflix_shows_seq'::regclass),\n\t\"type\" varchar(7) NOT NULL,\n\ttitle text NOT NULL,\n\tdirector text NULL,\n\tcast_members text NULL,\n\tcountry varchar(60) NOT NULL,\n\tdate_added date NOT NULL,\n\trelease_year int4 NOT NULL,\n\trating int4 NULL,\n\tduration_in_minute int4 NULL,\n\tlisted_in text NULL,\n\tdescription text NULL,\n\tCONSTRAINT netflix_shows_pkey PRIMARY KEY (id),\n\tCONSTRAINT netflix_shows_type_check CHECK (((type)::text = ANY (ARRAY[('MOVIE'::character varying)::text, ('TV_SHOW'::character varying)::text])))\n);\n```\n---\n\n## 🛠️ Installation \u0026 Setup\nA step by step series of examples that tell you how to get a development env running.\n1. Ensure you have **Git installed on your Windows** machine, then clone the repository to your local environment:\n```bash\ngit clone https://github.com/yoanesber/Spring-Boot-Hibernate-Native-Query-PostgreSQL.git\ncd Spring-Boot-Hibernate-Native-Query-PostgreSQL\n```\n\n2. Set up PostgreSQL\n- Run the provided DDL script to set up the database schema\n- Configure the connection in `.env.development` file:\n```properties\n# Database properties\nSPRING_DATASOURCE_PORT=5432\nSPRING_DATASOURCE_USERNAME=your_username\nSPRING_DATASOURCE_PASSWORD=your_password\nSPRING_DATASOURCE_DB=your_db\nSPRING_DATASOURCE_SCHEMA=your_schema\n```\n\n3. Run the application locally\n- Make sure PostgreSQL is running, then execute: \n```bash\nmvn spring-boot:run\n```\n\n4. Now, API is available at:  \n```bash\nhttp://localhost:8081/ \n```\n\nYou can test the API using: Postman (Desktop/Web version) or cURL\n\n---\n\n## 🌐 API Endpoints\nThe REST API provides a set of endpoints to manage Netflix shows, allowing clients to perform CRUD operations (Create, Read, Update, Delete). Each endpoint follows RESTful principles and accepts/returns JSON data. Below is a list of available endpoints along with sample requests.\n\n- `GET` http://localhost:8081/api/v1/netflix-shows - Retrieve all Netflix Shows.  \n- `GET` http://localhost:8081/api/v1/netflix-shows/1 - Retrieve a specific Netflix Show by ID.  \n\n**Successful Response:**\n```json\n{\n    \"statusCode\": 200,\n    \"timestamp\": \"2025-03-31T10:59:25.4794899\",\n    \"message\": \"NetflixShows retrieved successfully\",\n    \"data\": {\n        \"id\": 1,\n        \"showType\": \"MOVIE\",\n        \"title\": \"Sankofa\",\n        \"director\": \"Haile Gerima\",\n        \"castMembers\": \"Kofi Ghanaba, Oyafunmike Ogunlano, Alexandra Duah, Nick Medley, Mutabaruka, Afemo Omilami, Reggie Carter, Mzuri, Oliver\",\n        \"country\": \"United States\",\n        \"dateAdded\": \"2021-09-24\",\n        \"releaseYear\": 2024,\n        \"rating\": 10,\n        \"durationInMinute\": 90,\n        \"listedIn\": \"Comedy\",\n        \"description\": \"A woman adjusting to life after a loss contends with a feisty bird that's taken over her garden — and a husband who's struggling to find a way forward.\"\n    }\n}\n```\n\n- `POST` http://localhost:8081/api/v1/netflix-shows - Create a new Netflix Show.  \n\n**Request Body:**\n```json\n{\n    \"showType\":\"TV_SHOW\",\n    \"title\":\"The Smart Money Woman\",\n    \"director\":\"Bunmi Ajakaiye\",\n    \"castMembers\":\"Osas Ighodaro, Ini Dima-Okojie, Kemi Lala Akindoju, Toni Tones, Ebenezer Eno, Eso Okolocha DIke, Patrick Diabuah, Karibi Fubara, Temisan Emmanuel, Timini Egbuson\",\n    \"country\":\"India\",\n    \"dateAdded\":\"2021-09-16\",\n    \"releaseYear\":2020,\n    \"rating\":5,\n    \"durationInMinute\":90,\n    \"listedIn\":\"Romantic TV Shows\",\n    \"description\":\"Five glamorous millennials strive for success as they juggle careers, finances, love and friendships. Based on Arese Ugwu's 2016 best-selling novel.\"\n}\n```\n\n**Successful Response:**\n```json\n{\n    \"statusCode\": 201,\n    \"timestamp\": \"2025-03-31T11:00:44.0278893\",\n    \"message\": \"NetflixShows created successfully\",\n    \"data\": null\n}\n```\n\n- `PUT` http://localhost:8081/api/v1/netflix-shows/1 - Update an existing Netflix Show.  \n\n**Request Body:**\n```json\n{\n    \"showType\":\"TV_SHOW\",\n    \"title\":\"The Smart Money Woman\",\n    \"director\":\"Bunmi Ajakaiye\",\n    \"castMembers\":\"Osas Ighodaro, Ini Dima-Okojie, Kemi Lala Akindoju, Toni Tones, Ebenezer Eno, Eso Okolocha DIke, Patrick Diabuah, Karibi Fubara, Temisan Emmanuel, Timini Egbuson\",\n    \"country\":\"India\",\n    \"dateAdded\":\"2021-09-16\",\n    \"releaseYear\":2020,\n    \"rating\":5,\n    \"durationInMinute\":90,\n    \"listedIn\":\"TV Comedies\",\n    \"description\":\"Five glamorous millennials strive for success as they juggle careers, finances, love and friendships. Based on Arese Ugwu's 2016 best-selling novel.\"\n}\n```\n\n**Successful Response:**\n```json\n{\n    \"statusCode\": 200,\n    \"timestamp\": \"2025-03-31T11:01:48.4959796\",\n    \"message\": \"NetflixShows updated successfully\",\n    \"data\": null\n}\n```\n\n- `DELETE` http://localhost:8081/api/v1/netflix-shows/1 - Delete a Netflix Show.  \n```json\n{\n    \"statusCode\": 200,\n    \"timestamp\": \"2025-02-27T21:35:17.0110773\",\n    \"message\": \"NetflixShows deleted successfully\",\n    \"data\": null\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoanesber%2Fspring-boot-hibernate-native-query-postgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoanesber%2Fspring-boot-hibernate-native-query-postgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoanesber%2Fspring-boot-hibernate-native-query-postgresql/lists"}