Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

What is Spring Data JPA and how does it simplify database access? स्प्रिंग डेटा JPA क्या है और यह डेटाबेस एक्सेस को कैसे आसान बनाता है?

Answer

Spring Data JPA is an abstraction layer built on top of JPA (Java Persistence API) and Hibernate that eliminates most boilerplate DAO code. Instead of writing implementation classes for CRUD operations, you define an interface extending JpaRepository, and Spring generates the implementation at runtime using a dynamic proxy.

It provides out-of-the-box methods like save(), findById(), findAll(), and deleteById(), plus derived query methods generated from method names, pagination, sorting, and support for custom JPQL or native SQL queries — all with a fraction of the code required for plain JDBC or raw Hibernate.

public interface UserRepository extends JpaRepository<User, Long> {
    // save(), findById(), findAll(), deleteById() come for free
}

स्प्रिंग डेटा JPA, JPA (Java Persistence API) और Hibernate के ऊपर बना एक एब्सट्रैक्शन लेयर है जो अधिकतर बॉयलरप्लेट DAO कोड को समाप्त कर देता है। CRUD ऑपरेशन्स के लिए इम्प्लीमेंटेशन क्लास लिखने के बजाय, आप JpaRepository को एक्सटेंड करने वाला इंटरफेस डिफाइन करते हैं, और स्प्रिंग रनटाइम पर एक डायनामिक प्रॉक्सी का उपयोग करके इम्प्लीमेंटेशन जनरेट करता है।

यह save(), findById(), findAll(), और deleteById() जैसे रेडीमेड मेथड्स, मेथड नामों से जनरेट होने वाली डिराइव्ड क्वेरी मेथड्स, पेजिनेशन, सॉर्टिंग, और कस्टम JPQL या नेटिव SQL क्वेरीज़ का समर्थन प्रदान करता है।

public interface UserRepository extends JpaRepository<User, Long> {
    // save(), findById(), findAll(), deleteById() मुफ्त में मिलते हैं
}

Was this answer clear?