JAVA PERSISTENCE API / NOTES</>↗Java Persistence API17 Nov 2012
The following code example show you how to delete or remove entity object from database using JPA. The first class that we are going to create is ArtistDaoImpl which implements ArtistDao. This DAO class handles the delete process either by the entity ID or by the entity object itself. We define the delete process in […]
JAVA PERSISTENCE API / NOTES</>↗Java Persistence API17 Nov 2012
If you want to get the primary key of any JPA entity object you can use PersistenceUnitUtil.getIdentifier() method. This method take a single parameter which is the entity object whose identifier to be read. The PersistenceUnitUtil instance can be accessed from the EntityManagerFactory object. If the entity object contains an identifier the getIdentifier() method will […]
JAVA PERSISTENCE API / NOTES</>↗Java Persistence API13 Nov 2012
In this example you will learn how to update an entity object in JPA. We use the EntityManager.merge() method to update an entity. This method takes the entity to be saved as the parameter and return the merged entity back as the result. You can see a simple example to the code snippet below. Here […]
JAVA PERSISTENCE API / NOTES</>↗Java Persistence API12 Nov 2012
In this example you will learn how to find an entity object by its ID using JPA. To find entity by their ID, we use the EntityManager.find() method and pass the entity class and the entity ID as the parameters. In the code snippet below the EntityManager required by the ArtistDaoImpl will be passed from […]
JAVA PERSISTENCE API / NOTES</>↗Java Persistence API12 Nov 2012
In this example you are going to learn how to persist or save an entity object to database table using JPA. We are going to create a data access object (DAO) for persisting an Artist entity. We create a class called ArtistDaoImpl with a constructor that accept an EntityManager parameter. We provide a couple methods […]
JAVA PERSISTENCE API / NOTES</>↗Java Persistence API12 Nov 2012
In this code snippet you will learn how to create JPA EntityManagerFactory. This factory enable you to create the EntityManager which will be used to execute the JPA command to manipulate the database tables. To create the EntityManagerFactory you need to create to persistence.xml file first. The file is where you configure the JPA. This […]