In this post under hibrenate, I will explain how to delete a persisted object. We can delete a persisted object using Session interface delete method. Below is the complete code Main Class 1 import org.hibernate.Session; 2 import org.hibernate.SessionFactory; 3 4 public class HibernateDemo9 { 5 public static void main(String[] args) { 6 SessionFactory sessionFactory =…… Continue reading Deleting a persisted object
Session’s load vs get method
In this post under hibernate, I will introduce you to Session’s load and get method and explain their difference. Similarity 1) Both methods are used to load persistent object from the database 2) Both needs primary key id as a parameter Difference 1) If the persistent object identified by primary key is not there, then…… Continue reading Session’s load vs get method
Loading a Persistent Object
In this post under hibernate, I will explain how to load a persistent object from the database. We load a persistent object using Session interface “load” method. Several overloadded version of the “load” method exists, all these methods require the primary key id of the object to be loaded. Below is the complete code Main…… Continue reading Loading a Persistent Object
Custom Error Handling when parsing xml through SAX api
In this post under JAXP, I will explain how to add custom error handler when parsing xml document through SAX api. To provie a custom error handler, we need to implement the interface org.xml.sax.ErrorHandler as shown below package sax; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class CustomErrorHandler implements ErrorHandler { @Override public void error(SAXParseException…… Continue reading Custom Error Handling when parsing xml through SAX api
Rotating File Handler
In this post under logging, I will show how to create a rotating file handler. A rotating file handler create a set of files, with each file having a count in the file name indicating the total number of files created. Each file has a size limit, which when reached a new file is created…… Continue reading Rotating File Handler
Java Util Logging ErrorManager example
In this post under java logging, I will explain the purpose of ErrorManager and how we can use it. Whenever we write the below code logger.info(“Hello my name is Sumanth1”); We are requesting the Handler to log the message to a destination. What if an error happens at the Handler level when an attempt is…… Continue reading Java Util Logging ErrorManager example
JsonLineMapper Example
In this post under Spring Batch, I will explain the purpose of JsonLineMapper with an example. JsonLineMapper is used with reader bean for reading file containing JSON input as shown below JsonFileInput.txt {“id”:”id0″,”name”:”name0″,”status”:”status0″,”salary”:0}{“id”:”id1″,”name”:”name1″,”status”:”status1″,”salary”:1}{“id”:”id2″,”name”:”name2″,”status”:”status2″,”salary”:2}{“id”:”id3″,”name”:”name3″,”status”:”status3″,”salary”:3}{“id”:”id4″,”name”:”name4″,”status”:”status4″,”salary”:4}{“id”:”id5″,”name”:”name5″,”status”:”status5″,”salary”:5}{“id”:”id6″,”name”:”name6″,”status”:”status6″,”salary”:6}{“id”:”id7″,”name”:”name7″,”status”:”status7″,”salary”:7}{“id”:”id8″,”name”:”name8″,”status”:”status8″,”salary”:8}{“id”:”id9″,”name”:”name9″,”status”:”status9″,”salary”:9} Each line in the file is interpreted as a JSON object by JsonLineMapper. So each line must start with “{” and end…… Continue reading JsonLineMapper Example
Formatting batch file output
In this post under Spring Batch, I will show how to create batch files with formatted output. The example I use will generate output file where the width of the each fields are fixed. In all my previous posts under Spring Batch, the output of the examples generated will be as shown below Current Output…… Continue reading Formatting batch file output
Using JsonbCreator annotation
In this post under JSONB, I will explain the purpose of JsonbCreator annotation with an example. Whenever we deserialize a json data to java object, it is required that the Class of the object should have default/no argument constructor, so that JSONB runtime can create an instance of the class with the help of the…… Continue reading Using JsonbCreator annotation
Using Custom DateFormat
In this post, under JSONB, I will explain how to use custom date format when serializing/deserializing Java object containing date information to json format. By default JSONB when converting date information to json it prints in the format as shown below 2019-02-16T07:16:38.537Z[UTC] We can change this format globally, globally meaning the custom format will be…… Continue reading Using Custom DateFormat