In this post under Hibernate, I will explain how to create a unidirectional one to many association between objects using a mapping file with an example. For our example, we will create the below two tables. Data Definition Language CREATE TABLE `series1` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(50) NOT NULL, `description` VARCHAR(100) NOT…… Continue reading Unidirectional One to Many association mapping (without annotations)
Stubbing consecutive method calls
In this post under mockito, I will explain how to stub consecutive method calls with example. Consecutive method calls meaning sometimes we call same method multiple times. In that case we have to stub the method to return values consecutively. Below is the complete code for your reference Test Class 1 package package7; 2 3…… Continue reading Stubbing consecutive method calls
Stubbing a default interface method
In this post under Mockito, I will explain how to change a default interface method implementation for testing purposes with an example. For testing purposes I have created an interface as shown below Interface1 package package6; public interface Interface1 { public default int method1(int value) { return value * 2; } } The test case…… Continue reading Stubbing a default interface method
Mocking an interface
In this post under Mockito, I will show how to create a mock of an interface with an example Below is the complete example where I create a mock of java.util.List interface and call its method. Test Class 1 package package3; 2 3 import static org.junit.Assert.assertEquals; 4 import static org.mockito.Mockito.when; 5 6 import java.util.List; 7…… Continue reading Mocking an interface
SuffixRecordSeparatorPolicy example
In this post under Spring Batch, I will explain the purpose and how to use SuffixRecordSeparatorPolicy class with an example. SuffixRecordSeparatorPolicy class is a concrete implementation of org.springframework.batch.item.file.separator.RecordSeparatorPolicy interface. In one of my previous post I have explained the purpose of RecordSeparatorPolicy and how to use it. For recap, RecordSeparatorPolicy interface is used to tell…… Continue reading SuffixRecordSeparatorPolicy example
JsonRecordSeparatorPolicy example
In this post under Spring Batch, I will explain the purpose and how to use JsonRecordSeparatorPolicy class with an example. JsonRecordSeparatorPolicy class is a concrete implementation of org.springframework.batch.item.file.separator.RecordSeparatorPolicy interface. In one of my previous post I have explained the purpose of RecordSeparatorPolicy and how to use it. For recap, RecordSeparatorPolicy interface is used to tell…… Continue reading JsonRecordSeparatorPolicy example
Deleting a persisted object
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