APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents26 Nov 2012
This code snippet show you how to get the content-type of an HTTP Get request. The ContentType can be obtained by using ContentType.getOrDefault() method and passing an HttpEntity as the argument. The HttpEntity can be obtained from the HttpResponse object. From the ContentType object we can get the mime-type by calling the getMimeType() method. This […]
APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents26 Nov 2012
This example show you how to get HTTP response body as a string when using the Apache HttpComponents library. To get the response body as a string we can use the EntityUtils.toString() method. This method read the content of an HttpEntity object content and return it as a string. The content will be converted using […]
JAVA PERSISTENCE API / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]