Errors and solutions

[Resolved] Caused by: java.net.BindException: Address already in use: bind

Errors and solutions
In windows, run this below command, netstat -ano | findstr :9092 this command will list down all the processes which are running in this port (9092). To kill the process in windows run the below command taskkill /pid 21680 /f 21680 is the process id displayed after running the netstat above command. /f to kill the process forcefully. You will be able to see this response, SUCCESS: The process with PID 21680 has been terminated.

Developers Repeated Mistakes

Articles, Errors and solutions, Hibernate, Java
In this post we are going to discuss about the repeated mistakes of developers during design/implementation/planning etc. This is just a sudden thought process, so this post will grow on my day to day experience and research wise only. Feel free to comment your repeated mistakes to add it to this master list. In Hibernate/Databases: While creating/planning a column for description, we forget to define the length of values it can hold or even forget to think such scenarios. So always think about the value length for each and every column to design a proper optimistic design approaches: Bad: Here it can hold only till the default size of 255 length, where as, this field may get the value of length more than 255 as well, in that case this fails and all these type of issues can ...

[Solved] Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Errors and solutions
Full Error: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by   Root cause: This exception comes when we try to run the query with few fields in the select, but only one group by column field   Resolution: This issue comes in mysql 5.7, run the below command to disable the only_full_group_by in mysql: SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));     SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));   Note: Single quote alone may be different due to wordpres...

SOLVED: Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class

Errors and solutions
SOLVED: Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class: Root cause: If you are trying to populate result sets directly to your custom bean (not entity bean) then you must have public default constructor in your bean. See the below sample snippet to understand better.   Example: [java] @Query("SELECT new com.ngdeveloper.dto.SlugCountBean(t.tagSlug, count(c)) FROM Coupon c join c.tags t where c.couponEndDate >=CURRENT_DATE and t.tagType=:tagType GROUP BY t.tagSlug") List<SlugCountBean> findCouponCountsTagWise(@Param("tagType") String tagType); [/java]   SlugCountBean.java Bean | which is causing the issue: [java] public class SlugCountBean { private String slug; private long co...

[Solved] JSON parse error: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain:

Errors and solutions
[Solved] JSON parse error: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: Full Exception: [plain] {"timestamp":"2018-09-21T12:25:44.365+0000","status":400,"error":"Bad Request","message":"JSON parse error: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.ngdeveloper.entities.Coupon[\"store\"]->com.ngdeveloper.entities.Store[\"description\"])","path":"/ngdeveloper/api/rest/coupon/add"} [/plain]   Solution: By default jackson tries to serialize the class as well as all the fields of the class, so you could have got the null...

[Resolved] Spring boot JWT Filter called twice

Errors and solutions
[Resolved] Spring boot JWT Filter called twice: Recently when I was integrating JWT Filter and Simple CORS filter in my spring boot project, I observed that both the filters are called twice before actually reaching my servlet/rest controller.   After googling, I got this link, As per that, One invocation is by servlet container and the other is by Spring Security, so the filter will get called twice. So by adding this line in your JWT Filter bean implementation registrationBean.setEnabled(false); only the spring security calls for token, so JWT filter call twice issue will get resolved.   Issue Code: [Called twice] [java] @Bean public FilterRegistrationBean jwtFilter(){ final FilterRegistrationBean registrationBean = new FilterRegistrationBean(); registra

org.springframework.web.HttpMediaTypeNotAcceptableException | Could not find acceptable representation

Errors and solutions
org.springframework.web.HttpMediaTypeNotAcceptableException | Could not find acceptable representation: Full Error details: [plain] {"timestamp":1522250376646,"status":406,"error":"Not Acceptable","exception":"org.springframework.web.HttpMediaTypeNotAcceptableException","message":"Could not find acceptable representation","path":"/category/deleteImage/google.png"} [/plain]     As per this link, I found the solution for this issue:   Solution: [java] @SpringBootApplication public class CouponzcornerBackendApplication { public static void main(String[] args) { SpringApplication.run(CouponzcornerBackendApplication.class, args); } @Configuration public static class PathMatchingConfigurationAdapter extends WebMvcConfigurerAdapter { @O...

[Resolved] “org.springframework.web.HttpMediaTypeNotSupportedException” angular 5

Errors and solutions
Hi All, Recently I came across this "org.springframework.web.HttpMediaTypeNotSupportedException" error while trying to hit my spring boot rest web services application from angular 5.   I am posting my experience because to help someone quickly. I almost cross checked all the places many times, but I could not find the below miss which I found at last and also do remember this error says that "HttpMediaTypeNotSupportedException", so this error can happen due to incorrect media type/media type is not set or some spelling issue.   In my case, Error: "org.springframework.web.HttpMediaTypeNotSupportedException" Resolution: I just missed s in the header in the return this.http.post line, it should be headers, but I just mentioned s and wrote as as header. Before Fix

Understanding & Resolving “Too many connections” Exception

Errors and solutions
Understanding & Resolving "Too many connections" Exception:   Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections" Issue Fix: Close the open connections properly, because too many open connection error indicates too many connections are opened but not closed. Existing Code which has the issue:   In the below code, finally block still has the code snippet to close the too many connections exception. But I did very badly, closing the connection by opening it newly in finally block instead of the one used inside the try block. [java] public List<CouponDBPojo> getCouponzForPublish(int start, int rowLimit) { // int start = 10; // int r...