Posts

Showing posts from September, 2015

Spring 4 MVC + Hibernate 4 + Maven CRUD Example

Image
In my previous post, I have posted about Named Query and How to use named query here . After posting dozens of Hibernate Tutorial and Interview Questions on the internet, today I thought now the time has come to integrate two popular framework together. So in this post, I am going to show you a simple CRUD example of Hibernate with Spring 4 MVC integration. For those who are totally new to Spring MVC or want to learn step by step Hello World Tutorial in Spring MVC they can follow my previous spring mvc tutorial with example. Of course at the end of this article you can download the full crud example using our downloadable link. While implementing this tutorial, If you are encountered with java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet, exception than you can follow How to fix java.lang.ClassNotFoundException to fix the issue. After completion of this tutorial our output will looks like screens. listProduct.htm product.htm Tools and...

Core Java written test questions and answers for experienced set 1

Image
In my previous post, I have listed 20 JSP Servlet interview question . And recently, I went for an interview to collect few interview questions for my friends to post here. The organization is one of the world's well known Banking company. It's a product based company, when I went to their campus almost 200 candidates are their to appeared in interview. And the process was first technical written test following 1st and 2nd round of technical discussion than HR round. Although I have already listed 20 Core java interview question . In this post, I am going to share the questions asked in written test. The question is objective type and contains 20 question carrying 2 marks each question and passing score was 20. The Questions level is from basic to intermediate. Question 1. What will be the output of below program? package com.javamakeuse.poc; public class Test01 { public static int num = 20; public static void main(String[] args) { Test01 test01 = null; System.o...

Tutorial - Hibernate named query examples

Image
Now the named query. In my previous post, I have shared with you native query example here and How to use Criteria Query in Hibernate at Criteria Query Example . But Named Query is totally different than all these, SQL Query and HQL Query . What is Named Query :  Named Query is not a special query, It's just a way of placing your common queries at a single destination just like we put some constants in a enum or a single constant file which will help us to mange the things. The same way named query is just a way of putting the sql/hql query to single destination so that you can easily manage them at any point, and named queries are used by calling their name. How To Use Named Query: To use named query you need to define named queries in your mapped hbm.xml file or annotated pojo class, and then you need to call them by their name as the way you used in query with session. Syntax to defines named query in annotated java class. @NamedQueries({@NamedQuery(name = "", ...

Tutorial - Hibernate query cache example

Image
I have already posted about Hibernate First Level Cache and How second level cache works in Hibernate here . And now, In this post I am going to show you about how to use Query Cache in Hibernate. Hibernate Query Cache is used with Second level cache, before going to the code, let me list you few points about Query Cache and then we will dive into the coding, of course at last, I'll share you the link to download the complete example of Query Cache. Hibernate is very powerful ORM framework and it's Criteria Query and Hibernate Fetching strategies always very useful. How Query Cache Works : The Query Cache does not cached the entities unlike Second Level Cache, It cached the queries and the return identifiers of the entities. Once it cached the identifiers than, It took help from Hibernate Second level cache to load the entities based on the identifiers value. So Query cache always used with Second level cache to get better result, because only query cache will cached the i...