Java JPA Basics: Entities, EntityManager and JPQL

Su Suriya Ravichandran Updated 18 Nov 2026
14 min read ·Lesson 222 of 306

Java JPA (Jakarta Persistence API) is the standard way to save and load Java objects in a relational database without writing most of the SQL yourself. You mark a class as an entity, and JPA maps its fields to table columns, generates INSERT, UPDATE and SELECT statements, and turns result rows back into objects.

JPA removes the repetitive JDBC code you wrote in the previous lessons: setting parameters one by one, reading each column from a ResultSet, and building objects by hand. In this lesson you will set up a JPA project, map your first entity, save, find, update and delete objects with the EntityManager, understand entity lifecycle states, and query data with JPQL.


What Is JPA in Java?

JPA is a specification: a set of interfaces and annotations in the jakarta.persistence package. On its own it does nothing. A provider (also called an implementation) does the actual work of talking to the database.

NameWhat it is
Jakarta Persistence (JPA)The standard API: @Entity, EntityManager, JPQL, ...
Hibernate ORMThe most popular JPA provider, also used by Spring Boot
EclipseLinkThe reference JPA provider
JDBCThe lower layer every provider uses to run SQL

Your code imports only jakarta.persistence types, so in principle you can switch providers without changing it. This lesson uses Hibernate as the provider.

Note: Before 2020 the package was javax.persistence. When Java EE moved to the Eclipse Foundation and became Jakarta EE, the package was renamed to jakarta.persistence. Old tutorials using javax.persistence will not compile against current Hibernate versions.


Core JPA Concepts

ConceptMeaning
EntityA class annotated with @Entity; each object is one row in a table
Persistence unitA named configuration (database URL, entity classes, settings), usually in persistence.xml
EntityManagerFactoryCreated once per persistence unit; heavy, thread-safe, lives for the whole application
EntityManagerLight, not thread-safe; used for one unit of work, then closed
Persistence contextThe set of entity objects an EntityManager is currently tracking
EntityTransactionBegins, commits or rolls back a transaction when running outside a server
JPQLJakarta Persistence Query Language: SQL-like queries written against entities and fields, not tables and columns

Setting Up a Java JPA Project

You need a JPA provider and a JDBC driver. Hibernate brings the jakarta.persistence-api jar with it. The examples use the in-memory H2 database.

<dependencies>
    <dependency>
        <groupId>org.hibernate.orm</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>7.4.0.Final</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>2.3.232</version>
    </dependency>
</dependencies>

The project layout looks like this:

src/main/java/com/gocourse/jpa/Student.java
src/main/java/com/gocourse/jpa/SaveStudents.java
src/main/resources/META-INF/persistence.xml

The persistence unit is defined in src/main/resources/META-INF/persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_2.xsd"
             version="3.2">

    <persistence-unit name="school">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>com.gocourse.jpa.Student</class>

        <properties>
            <property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:school;DB_CLOSE_DELAY=-1"/>
            <property name="jakarta.persistence.jdbc.user" value="sa"/>
            <property name="jakarta.persistence.jdbc.password" value=""/>
            <property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
        </properties>
    </persistence-unit>
</persistence>

How it works:

  • name="school" is the name your code uses to create the EntityManagerFactory.
  • <class> lists the entity classes JPA should manage.
  • The jakarta.persistence.jdbc.* properties are standard and work with any provider.
  • drop-and-create makes JPA generate the tables from your entities at startup. It is handy for learning and tests; real applications manage the schema with migration tools such as Flyway or Liquibase instead.

Note: Hibernate needs Java 17 or newer. It also prints INFO log lines at startup. The outputs in this lesson show only what the programs print with System.out.


Your First JPA Entity

An entity is a normal Java class with a few annotations. JPA needs an @Id field and a no-argument constructor (it may be protected).

package com.gocourse.jpa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "students")
public class Student {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 40)
    private String name;

    @Column(nullable = false, unique = true, length = 60)
    private String email;

    private int marks;

    protected Student() {
        // required by JPA, which creates objects through this constructor
    }

    public Student(String name, String email, int marks) {
        this.name = name;
        this.email = email;
        this.marks = marks;
    }

    public Long getId() { return id; }
    public String getName() { return name; }
    public String getEmail() { return email; }
    public int getMarks() { return marks; }
    public void setMarks(int marks) { this.marks = marks; }

    @Override
    public String toString() {
        return "Student{id=" + id + ", name=" + name + ", marks=" + marks + "}";
    }
}

The table JPA generates from this class looks like:

students
+----+-------+-------------------+-------+
| id | name  | email             | marks |
+----+-------+-------------------+-------+

How it works:

  • @Entity tells JPA to manage this class. @Table(name = "students") sets the table name; without it the table would be called Student.
  • @Id marks the primary key, and @GeneratedValue(strategy = GenerationType.IDENTITY) lets the database assign it (an auto-increment column).
  • @Column customizes a column: nullable = false adds NOT NULL, unique = true adds a unique constraint, length sets the VARCHAR size.
  • Fields without annotations, such as marks, are still mapped, using the field name as the column name.
AnnotationPurpose
@EntityMarks a class as a persistent entity
@TableSets the table name and other table options
@IdMarks the primary key field
@GeneratedValueLets the database or provider generate key values
@ColumnSets column name, length, nullability and uniqueness
@TransientExcludes a field from the table

Saving Objects with persist()

To save a new object, open an EntityManager, start a transaction, call persist(), and commit.

package com.gocourse.jpa;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

public class SaveStudents {
    public static void main(String[] args) {
        try (EntityManagerFactory factory = Persistence.createEntityManagerFactory("school");
             EntityManager entityManager = factory.createEntityManager()) {

            Student asha = new Student("Asha", "asha@example.com", 88);
            Student ravi = new Student("Ravi", "ravi@example.com", 72);
            Student meena = new Student("Meena", "meena@example.com", 92);
            System.out.println("Id before persist: " + asha.getId());

            entityManager.getTransaction().begin();
            entityManager.persist(asha);
            entityManager.persist(ravi);
            entityManager.persist(meena);
            entityManager.getTransaction().commit();

            System.out.println("Saved: " + asha);
            System.out.println("Saved: " + ravi);
            System.out.println("Saved: " + meena);
        }
    }
}

Output:

Id before persist: null
Saved: Student{id=1, name=Asha, marks=88}
Saved: Student{id=2, name=Ravi, marks=72}
Saved: Student{id=3, name=Meena, marks=92}

How it works:

  • Persistence.createEntityManagerFactory("school") reads persistence.xml, connects to H2 and creates the students table.
  • persist() makes each object managed. With IDENTITY keys, JPA runs the INSERT right away so it can read back the generated id, which it writes into the object's id field.
  • commit() makes the inserts permanent. Both EntityManagerFactory and EntityManager are AutoCloseable in current JPA, so try-with-resources closes them.

Finding an Entity by Primary Key

find() loads one entity by its id. It returns null when no row has that id.

package com.gocourse.jpa;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

public class FindStudent {
    public static void main(String[] args) {
        try (EntityManagerFactory factory = Persistence.createEntityManagerFactory("school")) {

            try (EntityManager entityManager = factory.createEntityManager()) {
                entityManager.getTransaction().begin();
                entityManager.persist(new Student("Asha", "asha@example.com", 88));
                entityManager.persist(new Student("Ravi", "ravi@example.com", 72));
                entityManager.getTransaction().commit();
            }

            try (EntityManager entityManager = factory.createEntityManager()) {
                Student found = entityManager.find(Student.class, 2L);
                System.out.println("Found: " + found);
                System.out.println("Email: " + found.getEmail());

                Student missing = entityManager.find(Student.class, 99L);
                System.out.println("Id 99: " + missing);

                Student again = entityManager.find(Student.class, 2L);
                System.out.println("Same object on second find: " + (found == again));
            }
        }
    }
}

Output:

Found: Student{id=2, name=Ravi, marks=72}
Email: ravi@example.com
Id 99: null
Same object on second find: true

How it works:

  • The second EntityManager starts with an empty persistence context, so the first find() runs a SELECT and builds a Student from the row.
  • The key must match the type of the @Id field. The id is a Long, so the code passes 2L.
  • The second find() for id 2 does not touch the database. The persistence context already holds that entity, so it returns the same object. This is often called the first-level cache.

Updating Data with Dirty Checking

There is no update() method in JPA. You change a managed entity with its setters, and at commit JPA compares it with the state it loaded and writes an UPDATE for whatever changed. This is called dirty checking.

package com.gocourse.jpa;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

public class UpdateStudent {
    public static void main(String[] args) {
        try (EntityManagerFactory factory = Persistence.createEntityManagerFactory("school")) {

            try (EntityManager entityManager = factory.createEntityManager()) {
                entityManager.getTransaction().begin();
                entityManager.persist(new Student("Ravi", "ravi@example.com", 72));
                entityManager.getTransaction().commit();
            }

            try (EntityManager entityManager = factory.createEntityManager()) {
                entityManager.getTransaction().begin();
                Student ravi = entityManager.find(Student.class, 1L);
                ravi.setMarks(ravi.getMarks() + 8); // only a setter call, no SQL
                entityManager.getTransaction().commit(); // UPDATE happens here
            }

            try (EntityManager entityManager = factory.createEntityManager()) {
                System.out.println("After update: " + entityManager.find(Student.class, 1L));
            }
        }
    }
}

Output:

After update: Student{id=1, name=Ravi, marks=80}

How it works:

  • find() returns a managed Student, and JPA remembers a snapshot of its original values.
  • setMarks() only changes the Java object. At commit(), JPA notices that marks differs from the snapshot and runs UPDATE students SET ... WHERE id = 1.
  • The third EntityManager reads the row fresh from the database, proving the change was saved.

Deleting Data with remove()

remove() deletes a managed entity. The DELETE runs at commit.

package com.gocourse.jpa;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

public class DeleteStudent {
    public static void main(String[] args) {
        try (EntityManagerFactory factory = Persistence.createEntityManagerFactory("school");
             EntityManager entityManager = factory.createEntityManager()) {

            entityManager.getTransaction().begin();
            entityManager.persist(new Student("Kavin", "kavin@example.com", 64));
            entityManager.getTransaction().commit();

            entityManager.getTransaction().begin();
            Student kavin = entityManager.find(Student.class, 1L);
            entityManager.remove(kavin);
            entityManager.getTransaction().commit();

            System.out.println("After remove: " + entityManager.find(Student.class, 1L));
        }
    }
}

Output:

After remove: null

How it works:

  • remove() only works on a managed entity, so the code first loads Kavin with find().
  • After the commit the row is gone, and find() returns null.

JPA Entity Lifecycle States

Every entity object is in one of four states. Knowing the state tells you whether your changes will be saved.

StateMeaningHow it gets there
New (transient)Plain Java object; JPA does not know itnew Student(...)
ManagedTracked by an EntityManager; changes are saved at commitpersist(), find(), query results, merge() result
DetachedHas an id, but its EntityManager is closed or it was detachedclose(), clear(), detach()
RemovedScheduled for deletion at commitremove()

contains() tells you whether an object is managed by a given EntityManager.

package com.gocourse.jpa;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

public class LifecycleStates {
    public static void main(String[] args) {
        try (EntityManagerFactory factory = Persistence.createEntityManagerFactory("school");
             EntityManager entityManager = factory.createEntityManager()) {

            Student asha = new Student("Asha", "asha@example.com", 88);
            System.out.println("New - managed? " + entityManager.contains(asha));

            entityManager.getTransaction().begin();
            entityManager.persist(asha);
            System.out.println("After persist - managed? " + entityManager.contains(asha));
            entityManager.getTransaction().commit();

            entityManager.detach(asha);
            System.out.println("After detach - managed? " + entityManager.contains(asha));
            asha.setMarks(95); // not tracked: asha is detached

            entityManager.getTransaction().begin();
            Student managedCopy = entityManager.merge(asha); // copies asha's state into a managed instance
            System.out.println("merge result managed? " + entityManager.contains(managedCopy)
                    + ", same object as asha? " + (managedCopy == asha));
            entityManager.getTransaction().commit();

            entityManager.getTransaction().begin();
            entityManager.remove(managedCopy);
            System.out.println("After remove - managed? " + entityManager.contains(managedCopy));
            entityManager.getTransaction().commit();
        }
    }
}

Output:

New - managed? false
After persist - managed? true
After detach - managed? false
merge result managed? true, same object as asha? false
After remove - managed? false

How it works:

  • A new object is unknown to JPA until persist().
  • detach() stops tracking, so setMarks(95) alone would never reach the database.
  • merge() does not attach the detached object itself. It loads (or reuses) a managed instance with the same id, copies the detached object's values into it, and returns that managed copy. The new marks are saved at commit.
  • remove() moves the managed copy to the removed state, and the row is deleted at commit.

Note: A common bug is changing a detached object and expecting it to be saved. Always keep using the object returned by merge(), not the one you passed in.


Querying Data with JPQL

JPQL looks like SQL but works with entity names and field names. You write Student and s.marks, not students and the column name, and JPA translates it into SQL for your database.

package com.gocourse.jpa;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import jakarta.persistence.TypedQuery;

import java.util.List;

public class JpqlQueries {
    public static void main(String[] args) {
        try (EntityManagerFactory factory = Persistence.createEntityManagerFactory("school");
             EntityManager entityManager = factory.createEntityManager()) {

            entityManager.getTransaction().begin();
            entityManager.persist(new Student("Asha", "asha@example.com", 88));
            entityManager.persist(new Student("Ravi", "ravi@example.com", 72));
            entityManager.persist(new Student("Meena", "meena@example.com", 92));
            entityManager.persist(new Student("Kavin", "kavin@example.com", 64));
            entityManager.getTransaction().commit();

            // 1. Filtered and sorted list with a named parameter
            TypedQuery<Student> topQuery = entityManager.createQuery(
                    "SELECT s FROM Student s WHERE s.marks >= :minMarks ORDER BY s.marks DESC", Student.class);
            topQuery.setParameter("minMarks", 80);
            List<Student> topStudents = topQuery.getResultList();
            System.out.println("Marks >= 80:");
            topStudents.forEach(student -> System.out.println("  " + student.getName() + " " + student.getMarks()));

            // 2. A single value
            Long total = entityManager.createQuery("SELECT COUNT(s) FROM Student s", Long.class)
                    .getSingleResult();
            Double average = entityManager.createQuery("SELECT AVG(s.marks) FROM Student s", Double.class)
                    .getSingleResult();
            System.out.println("Total students: " + total + ", average: " + average);

            // 3. Selecting one field with LIKE
            List<String> names = entityManager.createQuery(
                            "SELECT s.name FROM Student s WHERE s.email LIKE :pattern ORDER BY s.name", String.class)
                    .setParameter("pattern", "%a%@example.com")
                    .getResultList();
            System.out.println("Emails with 'a' before @: " + names);
        }
    }
}

Output:

Marks >= 80:
  Meena 92
  Asha 88
Total students: 4, average: 79.0
Emails with 'a' before @: [Asha, Kavin, Meena, Ravi]

How it works:

  • createQuery(jpql, Student.class) returns a TypedQuery<Student>, so getResultList() gives a List<Student> with no casting.
  • :minMarks is a named parameter, filled with setParameter(). Like PreparedStatement placeholders, parameters keep you safe from SQL injection.
  • COUNT returns a Long and AVG returns a Double. getSingleResult() returns exactly one value. The average is (88 + 72 + 92 + 64) / 4 = 79.0.
  • You can select a single field (s.name) instead of the whole entity. All four email addresses contain an a before the @, so all four names come back, sorted.

Note: Never build JPQL by string concatenation with user input, such as "... WHERE s.name = '" + input + "'". Use parameters, for the same reasons explained in Java PreparedStatement.


Real-World Example: A Student Service with JPA

Real code wraps JPA calls in a service class. Each method is one unit of work: it gets an EntityManager, runs inside a transaction and returns plain results. Jakarta Persistence 3.2 adds runInTransaction() and callInTransaction() to the factory, which create the EntityManager, begin, commit (or roll back on an exception) and close for you.

package com.gocourse.jpa;

import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

import java.util.List;

public class StudentServiceApp {

    static class StudentService {
        private final EntityManagerFactory factory;

        StudentService(EntityManagerFactory factory) {
            this.factory = factory;
        }

        Long enroll(String name, String email, int marks) {
            if (marks < 0 || marks > 100) {
                throw new IllegalArgumentException("Marks must be 0-100, got " + marks);
            }
            return factory.callInTransaction(entityManager -> {
                Student student = new Student(name, email, marks);
                entityManager.persist(student);
                return student.getId();
            });
        }

        void addBonus(Long studentId, int bonus) {
            factory.runInTransaction(entityManager -> {
                Student student = entityManager.find(Student.class, studentId);
                if (student == null) {
                    throw new IllegalArgumentException("No student with id " + studentId);
                }
                student.setMarks(Math.min(100, student.getMarks() + bonus)); // saved by dirty checking
            });
        }

        List<Student> rankAbove(int minMarks) {
            return factory.callInTransaction(entityManager -> entityManager
                    .createQuery("SELECT s FROM Student s WHERE s.marks >= :min ORDER BY s.marks DESC, s.name", Student.class)
                    .setParameter("min", minMarks)
                    .getResultList());
        }

        boolean withdraw(Long studentId) {
            return factory.callInTransaction(entityManager -> {
                Student student = entityManager.find(Student.class, studentId);
                if (student == null) {
                    return false;
                }
                entityManager.remove(student);
                return true;
            });
        }
    }

    public static void main(String[] args) {
        try (EntityManagerFactory factory = Persistence.createEntityManagerFactory("school")) {
            StudentService service = new StudentService(factory);

            Long ashaId = service.enroll("Asha", "asha@example.com", 88);
            Long raviId = service.enroll("Ravi", "ravi@example.com", 72);
            Long meenaId = service.enroll("Meena", "meena@example.com", 92);
            Long kavinId = service.enroll("Kavin", "kavin@example.com", 64);
            System.out.println("Enrolled ids: " + List.of(ashaId, raviId, meenaId, kavinId));

            try {
                service.enroll("Divya", "divya@example.com", 120);
            } catch (IllegalArgumentException e) {
                System.out.println("Rejected: " + e.getMessage());
            }

            service.addBonus(raviId, 10);
            service.addBonus(meenaId, 10); // capped at 100

            System.out.println("Withdrew Kavin: " + service.withdraw(kavinId));
            System.out.println("Withdrew id 99: " + service.withdraw(99L));

            System.out.println("Students with 80 or more:");
            for (Student student : service.rankAbove(80)) {
                System.out.println("  " + student.getName() + " - " + student.getMarks());
            }
        }
    }
}

Output:

Enrolled ids: [1, 2, 3, 4]
Rejected: Marks must be 0-100, got 120
Withdrew Kavin: true
Withdrew id 99: false
Students with 80 or more:
  Meena - 100
  Asha - 88
  Ravi - 82

How it works:

  1. One factory, many short units of work. The EntityManagerFactory is created once in main and passed to the service. Each method gets its own short-lived EntityManager through runInTransaction() or callInTransaction().
  2. Validation before the database. enroll() rejects Divya's marks of 120 in Java, so nothing is written.
  3. Updates through dirty checking. addBonus() only calls setMarks(). Ravi goes from 72 to 82; Meena would reach 102 but Math.min caps her at 100.
  4. Automatic rollback. If a lambda throws, for example when addBonus() gets an unknown id, the transaction is rolled back before the exception reaches the caller.
  5. JPQL for reports. rankAbove(80) returns Meena, Asha and Ravi, sorted by marks and then name. Kavin was withdrawn, so he no longer appears.

Under the hood every one of these calls still borrows a JDBC connection, which is why the Java connection pooling lesson matters even when you use JPA, and why commit and rollback follow the same rules as in Java JDBC Transactions. The next lesson looks at Hibernate itself, the provider behind these examples, and its own native API.

0 Comments

Reviewed before they appear

No comments yet.

Java
Java Introduction Java Features Java Syntax Java Comments Java Statements Java Output Java Variables Java Data Types Java Type Casting Java Operators Java Strings Java Numbers Java Math Java Booleans Java User Input Java Conditions Java If Else Java Switch Java While Loop Java For Loop Java Break Java Continue Java Arrays Java Methods Java Parameters Java Return Values Java Scope Java Recursion Install Java Install JDK Java IDEs Java JDK Java JRE Java JVM Java Compiler Java File Compile Java Run Java JShell Basics Java Packages Java OOP Java Classes Java Objects Class Methods Constructors Constructor Overload this Keyword static Keyword final Keyword Encapsulation Inheritance Polymorphism Abstraction Access Modifiers super Keyword Method Overload Method Override Instanceof Operator Nested Classes Inner Classes Anonymous Classes Enums Records Array Basics Array Length Loop Arrays Multidimensional Arrays Array Copy Array Sorting Array Search ArrayList LinkedList HashSet TreeSet HashMap TreeMap Queue Interface Deque Interface Stack Class Iterator List Interface Set Interface Map Interface Collections Class Comparable Comparator Generics Basics Generic Classes Generic Methods Wildcards String Basics String Length String Methods String Concatenation String Compare String Search String Replace String Split String Format StringBuilder StringBuffer Text Blocks Regular Expressions Number Types Integer Class Float Class Double Class BigInteger BigDecimal Math Class Random Numbers Number Format Date Basics LocalDate LocalTime LocalDateTime ZonedDateTime Date Formatting Date Parsing Period Class Duration Class Java Instant Class Java Exception Basics Java try...catch Java Multiple Catch Blocks Java finally Block Java throw Keyword Java throws Keyword Java Checked Exceptions Java Unchecked Exceptions Java Custom Exceptions Java try-with-resources Java Exception Chaining Java File Basics Java Create Files Java Read Files Java Write Files Java Delete Files Java File Paths Java File Class Java BufferedReader Java BufferedWriter Java FileInputStream Java FileOutputStream Java Object Streams Java Directory Handling Java NIO Basics Java Files API Java Input Java Scanner Class Java Console Input Java PrintStream Java InputStream Java OutputStream Java Reader Class Java Writer Class Java Buffered Streams Java Data Streams Java Generics Introduction Java Generic Types Java Generic Methods Java Bounded Types Java Wildcards Java Type Erasure Java Generic Interfaces Java Generic Collections Java Lambda Basics Java Lambda Syntax Java Functional Interfaces Java Method References Java Stream API Java Stream Creation Java Stream Filter Java Stream Map Java Stream Reduce Java Stream Sort Java Stream Collect Java Collectors Class Java Optional Class Java Parallel Streams Java Threads: Thread Basics Create a Thread in Java Java Thread Class Java Runnable Interface Java Thread States Java Thread Sleep Java Thread Join Java Thread Priority Java Synchronization Java Thread Safety Java Race Conditions Java Deadlocks Java Executor Service Java Thread Pools Java Callable Interface Java Future Interface Java CompletableFuture Java Concurrent Collections Java Atomic Classes Java Virtual Threads Java Networking Basics Java URL Class Java URI Class Java HttpClient Java HTTP Requests Java HTTP Responses Java Socket Basics Java ServerSocket Java DatagramSocket Java WebSocket Basics Java JDBC Basics Java JDBC Setup Java Database Connection Java JDBC Connection Interface Java JDBC Statement Java PreparedStatement Java ResultSet Java JDBC CRUD Operations Java JDBC Transactions Java JDBC Batch Update Java Connection Pooling with HikariCP Java JPA Basics: Entities, EntityManager and JPQL Java Hibernate Basics: SessionFactory, Session and HQL Package in Java: Basics Explained with Examples Create Package in Java: Step-by-Step Guide with Examples Import Package in Java: The import Statement Explained Access Control in Java: Packages, Classes and Members JAR File in Java: Create, Run and Inspect JAR Files Java Modules: Introduction to the Java Module System module-info in Java: Every Module Directive Explained Java Module Path: How --module-path Finds Your Modules Java Classpath: How -cp and CLASSPATH Find Your Classes Java Annotations: Basics of @ Metadata in Java Java Built-in Annotations: @Override, @Deprecated and More Java Custom Annotations: Create Your Own @interface Java Annotation Targets: @Target and ElementType Explained Java Reflection API: Inspect and Use Classes at Runtime Java Class Metadata: Names, Modifiers, Hierarchy and Generic Java Dynamic Objects: Create Objects Dynamically With Reflec Java Dynamic Proxy: Intercept Method Calls With Proxy and In Java Security Java Secure Coding Java Password Hashing Java Input Validation Java Cryptography Basics Java KeyStore Basics Java TLS Basics Java SecureRandom Java JUnit Basics Java JUnit Test Methods JUnit Assertions JUnit Test Fixtures JUnit Parameterized Tests Mockito in Java Java Mock Objects Java Integration Testing Java Code Coverage Maven in Java Create a Maven Project in Java Maven Dependencies Maven Plugins Gradle in Java Gradle Build Gradle Dependencies Build Executable JAR in Java Build WAR File in Java HTTP Basics in Java Java Servlet Basics Servlet Lifecycle in Java HttpServletRequest in Java HttpServletResponse in Java JSP in Java JSTL in JSP REST API in Java JSON in Java Java Web Application Spring Framework Basics Spring Boot Tutorial Spring MVC Spring Data JPA Spring Security Spring Boot REST API Jakarta EE Basics Java Deployment JAR Deployment Java WAR Deployment Run Java as a Service Docker Java: Dockerize a Java Application Java Environment Variables and Configuration Java Logging Basics Java Production Setup Java JVM Options Java JVM Monitoring Java Hello World App Java Calculator App Java Number Guess Game Java Student Manager Java Library System Java Bank App Java Todo App Java File Manager Java Quiz App Java REST API Project Java Chat Server Java Employee Manager Java E-commerce API
Ask about this post
AI Ask about this post

Ask questions about Java JPA Basics: Entities, EntityManager and JPQL and get answers drawn from it.

Signed-in readers only.