Posts

Aggregate function with spring data

Image
I was working on a small project. Requirement was different in term of object mapping. There is simple way to map  java object with database table. Aggregate function in query is not mapped with entity class. We don't have direct mapping attribute in JPA annotation to map aggregate function with entity class. Spring data support this using interface. In ORM query we use aggregate function e.g. count , sum etc. the output of these aggregate function cannot directly map with the Entity class. To collect the outcome of aggregate methods. We need to map using interface in java and provide the Interface class with mapping method.      public List<ITeacherReport> getTeacherReport(String teacherName); Our requirement is to count solved question per month by teacher from answer table. We have below environment configuration. Thymeleaf (for view,  this is template engine) JDK 1.8 Maven Springboot framework  MySql  for database operation Open the start....

Why can't we override System class methods in Java

Image
Below is a link to the source code of the system class of Java's LANG package. Which I have taken from the internet. http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/cf44386c8fe3/src/share/classes/java/lang/System.java There are two main points 1. The system class is a final class. It cannot be extended. If we are declaring someone as a finalist then it means that it will not be expanded further. You are in a situation from which you should not move forward. 2. Perhaps you never tried to look at the System class. If you would have seen by opening the system class, then you would know that all its methods are static. Now you know about the static method, then you will also know that these methods will be loaded with the class. Static methods  are common to all object of same class. If a method is static, it cannot be overridden. I am assuming here that you know to override a method of  class, S...

Java Persistence API with Spring Data

Image
Let's try to build simple java application with the help of Spring Tool Suites IDE, Spring-Data connecting and MySql's relation database. You are free to choose any IDE (STS, Eclipse, Intellij etc).  We are building simple application which is storing User information into MySQL Database table. Our Requirements are simple IDE (any IDE, STS, Eclipse or Intellij) JDK 1.8 later  Maven 3.2 Create a Maven project using spring initializr   Open the Spring Initializr ( https://start.spring.io/  ).  This is the best way to start the project. Type the https://start.spring.io on url browser  The Initializr provides quick solution to place dependency and create project structure. Our requirement is JPA and MySql dependencies. below image shows the Initializr with required dependency selection: Following  pom.xml  file  will be generated having   spring-boot-starter-data  and   mysql-con...