Employee Management System Data Layer

Learn via video courses
Topics Covered

Overview

Repository is a way to interact with the database. Spring boot offers out of box repository to interact with Database with a minimum amount of the code.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Prerequisite

  • Reader should checkout and go through the following code.

Add Required Dependencies

We are going to build a data layer using MySQL, therefore dependencies we need are starter-data-jpa dependency and MySQL driver.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Configure Datasource

We need to configure the required properties in order to configure MySQL data source in application.properties

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Create Entity

Let's create an Employee entity in the com.scaler.ems.entities package and add the following content to it:

Create a Repository

Create an EmployeeRepository and extend it from JpaRepository

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Create Tables

There are several ways to create the table in the database but for this article, we will use hibernate way to create a table during application startup.

The above property creates a table in the target schema if it does not exist.

Unit Test Repositories

Spring Boot provides the @DataJpaTest annotation to test Spring Data JPA repositories or any other JPA-related components. @DataJpaTest connect to h2 database. Therefore we need to add h2 dependency in our pom with scope test.

Let's write a test case for repository EmployeeRepositoryTest

The source code for this article is available at the GitHub location under tag version_4.0.0_DL_FINAL

Conclusion

In this article, we have covered the following:

  • Build data layer for spring boot.
  • Test data layer using @DataJpaTest annotation.