|
| 1 | +{ |
| 2 | + "id": 101, |
| 3 | + "slug": "jpa-vs-jakarta-data", |
| 4 | + "title": "JPA versus Jakarta Data", |
| 5 | + "category": "enterprise", |
| 6 | + "difficulty": "intermediate", |
| 7 | + "jdkVersion": "21", |
| 8 | + "oldLabel": "Jakarta EE 8+", |
| 9 | + "modernLabel": "Jakarta EE 11+", |
| 10 | + "oldApproach": "JPA EntityManager", |
| 11 | + "modernApproach": "Jakarta Data Repository", |
| 12 | + "oldCode": "@PersistenceContext\nEntityManager em;\n\npublic User findById(Long id) {\n return em.find(User.class, id);\n}\n\npublic List<User> findByName(String name) {\n return em.createQuery(\n \"SELECT u FROM User u WHERE u.name = :name\",\n User.class)\n .setParameter(\"name\", name)\n .getResultList();\n}\n\npublic void save(User user) {\n em.persist(user);\n}", |
| 13 | + "modernCode": "@Repository\npublic interface Users extends CrudRepository<User, Long> {\n List<User> findByName(String name);\n}", |
| 14 | + "summary": "Declare a repository interface and let Jakarta Data generate the DAO implementation automatically.", |
| 15 | + "explanation": "Jakarta Data (Jakarta EE 11) turns data access into a pure interface declaration. You annotate an interface with @Repository and extend a built-in repository type such as CrudRepository. The runtime generates the implementation — including derived queries from method names like findByName — so there is no EntityManager boilerplate, no JPQL strings, and no hand-written save/find methods.", |
| 16 | + "whyModernWins": [ |
| 17 | + { |
| 18 | + "icon": "🪄", |
| 19 | + "title": "Zero boilerplate", |
| 20 | + "desc": "Declare the interface; the container generates the full DAO implementation at deploy time." |
| 21 | + }, |
| 22 | + { |
| 23 | + "icon": "🔍", |
| 24 | + "title": "Derived queries", |
| 25 | + "desc": "Method names like findByNameAndStatus are parsed automatically — no JPQL or SQL needed." |
| 26 | + }, |
| 27 | + { |
| 28 | + "icon": "🔌", |
| 29 | + "title": "Portable", |
| 30 | + "desc": "Any Jakarta EE 11 compliant runtime provides the repository implementation with no vendor lock-in." |
| 31 | + } |
| 32 | + ], |
| 33 | + "support": { |
| 34 | + "state": "available", |
| 35 | + "description": "Available since Jakarta EE 11 / Java 21 (2024)" |
| 36 | + }, |
| 37 | + "prev": "enterprise/jdbc-vs-jpa", |
| 38 | + "next": null, |
| 39 | + "related": [ |
| 40 | + "enterprise/jdbc-vs-jpa", |
| 41 | + "enterprise/ejb-vs-cdi", |
| 42 | + "enterprise/servlet-vs-jaxrs" |
| 43 | + ], |
| 44 | + "docs": [ |
| 45 | + { |
| 46 | + "title": "Jakarta Data 1.0 Specification", |
| 47 | + "href": "https://jakarta.ee/specifications/data/1.0/" |
| 48 | + }, |
| 49 | + { |
| 50 | + "title": "Jakarta Data 1.0 API", |
| 51 | + "href": "https://jakarta.ee/specifications/data/1.0/apidocs/" |
| 52 | + } |
| 53 | + ] |
| 54 | +} |
0 commit comments