org.postgresql.util.PSQLException: ERROR: cannot cast type bytea to uuid

I was stuck solving this weird exception while working on a Spring Boot and Hibernate application. I verified all the configuration settings, double-checked the API calls and still, I was clueless as to what was actually causing the problem. The only conclusion that I had – The error occurs when there is a null value being sent a placeholder to the query.

Continue reading

Using Apache POI to create Excel File – Part I

Systems of any scale are holding data in one form or the other (Database, files, images, videos etc). With more and more data being churned out every day, there is also a need to be able to export data from the Applications. The exported data should be made available in the format that users can easily view with bunch of other tools. Excel is one of those dominating tool that people love for its multipurpose application. In this article, we will learn how to leverage Apache POI to generate Excel sheet with various customization options.

Continue reading

Java 8 streams API

My experience with querying a collection has always been clumsy. Writing iterative loops, adding nested if conditions and above all the hack of maintaining intermediary collection to store results. On top of that the brutal indicators from SonarQube – cyclomatic complexity. During all this, I felt there is a common pattern for filtering, sorting and there has to be an expressive way to achieve this functionality(someone said more like SQL!!!). With my love towards multiple technologies (Ok I accept I am a polyglot coder), I knew .Net already had an answer to this – LINQ. Simply have a collection and write a query to extract data. Something like below
Continue reading

What is lambda? and why do we need it?

When I started coding GUI application using Java, I realized my code was cluttered with too many anonymous classes. Each time, I had to handle an event the inlined implementation of ActionListener introduced nested and unreadable lines of code. How many of you have written code like below

signUpUserBtn.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){

Continue reading

Is it wise to use unsafe – Hidden secret of Java

I have been visiting quite a few sites and going through few forums, when I stumbled upon an article talking about the hidden weapon of Java, not made publicly known due to some reasons. But it is claimed that many of the Java internals and third party softwares do use this API to gain monstrous power.
While we have learned from academic days that heap space is home for Java objects, it is a place where the objects come to life and die. JVM with its GC algorithm makes the kill and creates space for new objects. While in the process of moving objects from various places (eden, young generator etc), it sometimes may bring down the application performance to its knees and can prove costly affair.
Whlie GC has been seen as life savior for people who dont want to worry about memory management, it also imposed restriction in terms of no control over deciding fate of the object as when it will get garbage collected. While this may not sound so serious problem as people end up allocating higher heap space for JVM (without realising the fact that it is actually hampering performance), some felt it bit uncomfortable (geeks from C, C++ playing with memory functions).
Continue reading