Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked
()
About this ebook
- 300 Hibernate, Spring & Struts Interview Questions
- 78 HR Interview Questions
- Real life scenario based questions
- Strategies to respond to interview questions
- 2 Aptitude Tests
Read more from Vibrant Publishers
Core Java Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 4 out of 5 stars4/5Stakeholder Engagement Essentials You Always Wanted To Know: Self Learning Management Rating: 5 out of 5 stars5/5SAP HANA Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsOperations and Supply Chain Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsHR Analytics Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsProject Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsLeadership Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsDigital SAT Reading and Writing Practice Questions: Test Prep Series Rating: 5 out of 5 stars5/5Business Strategy Essentials You Always Wanted To Know: Self Learning Management Rating: 5 out of 5 stars5/5GRE Master Wordlist: 1535 Words for Verbal Mastery: Test Prep Series Rating: 4 out of 5 stars4/5Organizational Behavior Essentials You Always Wanted To Know: Self Learning Management Rating: 5 out of 5 stars5/5Financial Management Essentials You Always Wanted to Know: 5th Edition: Self Learning Management Rating: 0 out of 5 stars0 ratingsDiversity in the Workplace Essentials You Always Wanted To Know: Self Learning Management Rating: 5 out of 5 stars5/5Advanced Java Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 1 out of 5 stars1/5Microeconomics Essentials You Always Wanted to Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsGMAT Analytical Writing: Solutions to the Real Argument Topics: Test Prep Series Rating: 4 out of 5 stars4/5Business Law Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsPython Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsAdvanced C++ Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsJava/J2EE Design Patterns Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsHuman Resource Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsRestful Java Web Services Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsC & C++ Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsFinancial Accounting Essentials You Always Wanted to Know: 5th Edition: Self Learning Management Rating: 0 out of 5 stars0 ratingsAdvanced SAS Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsWriting Impressive College Essays: Test Prep Series Rating: 0 out of 5 stars0 ratingsSQL Server Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsSAS Programming Guidelines Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsBase SAS Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsCCNA Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratings
Related to Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked
Titles in the series (33)
CORE JAVA Interview Questions You'll Most Likely Be Asked Rating: 4 out of 5 stars4/5SQL Server Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdvanced JAVA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsC & C++ Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSoftware Testing Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsHibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsC# Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsData Structures & Algorithms Interview Questions You'll Most Likely Be Asked Rating: 1 out of 5 stars1/5JavaScript Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava / J2EE Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsHadoop BIG DATA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsORACLE PL/SQL Interview Questions You'll Most Likely Be Asked Rating: 5 out of 5 stars5/5JSP-Servlet Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSAP HANA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdvanced C++ Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsPython Interview Questions You'll Most Likely Be Asked Rating: 2 out of 5 stars2/5UNIX Shell Programming Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAutomated Software Testing Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsCCNA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsBase SAS Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsOperating Systems Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsLinux System Administrator Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdvanced SAS Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsIBM WebSphere Application Server Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSAS Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSAS Programming Guidelines Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava/J2EE Design Patterns Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsRESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsCloud Computing Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratings
Related ebooks
Java/J2EE Design Patterns Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsJava / J2EE Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSpring Boot Intermediate Microservices: Resilient Microservices with Spring Boot 2 and Spring Cloud Rating: 0 out of 5 stars0 ratingsJSP-Servlet Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsRapid Java Web Development Rating: 0 out of 5 stars0 ratingsThe Java Workshop: Learn object-oriented programming and kickstart your career in software development Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java: Java Computer Programming, #2 Rating: 0 out of 5 stars0 ratingsMastering Symfony Rating: 0 out of 5 stars0 ratingsAdvanced JAVA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSpring and Spring Boot Interview Questions and Answers. Tech interviewer’s notes Rating: 5 out of 5 stars5/5Java Multithreading Interview Questions And Answers Rating: 0 out of 5 stars0 ratingsRESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsSpring Security 3.x Cookbook Rating: 0 out of 5 stars0 ratingsJava Core Interview in Australia. Questions and Answers. Tech interviewer’s notes Rating: 0 out of 5 stars0 ratingsSpring Boot 2: How To Get Started and Build a Microservice - Third Edition Rating: 5 out of 5 stars5/5Spring Boot and Single-Page Applications: Securing Your API with a Single-Page Application Frontend - Second Edition Rating: 0 out of 5 stars0 ratingsCORE JAVA Interview Questions You'll Most Likely Be Asked Rating: 4 out of 5 stars4/5Spring Boot Cookbook Rating: 0 out of 5 stars0 ratingsJava Core Interview Questions and Answers. Tech interviewer’s notes Rating: 1 out of 5 stars1/5Brush-up java for Interview Rating: 5 out of 5 stars5/5Angular Interview Questions and Answers: Including Angular 6,5,4 and 2 Rating: 0 out of 5 stars0 ratingsMockito Essentials Rating: 3 out of 5 stars3/550 Recipes for Programming Angular Rating: 4 out of 5 stars4/5
Programming For You
HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsLearn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5The Unofficial Guide to Open Broadcaster Software: OBS: The World's Most Popular Free Live-Streaming Application Rating: 0 out of 5 stars0 ratingsCoding All-in-One For Dummies Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Python Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratingsSQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5The Little SAS Book: A Primer, Sixth Edition Rating: 5 out of 5 stars5/5Teach Yourself C++ Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Web Designer's Idea Book, Volume 4: Inspiration from the Best Web Design Trends, Themes and Styles Rating: 4 out of 5 stars4/5
Reviews for Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked
0 ratings0 reviews
Book preview
Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked - Vibrant Publishers
Hibernate Interfaces
1: Explain Database Transaction management using Transaction Interface.
Answer:
In Hibernate, every transaction is handled by a session object. It controls the transactions and hides it from the outer world. To make sure the transaction completes successfully and is committed upon success and is rolled back upon failure, the entire transaction happens within a try – catch block. Within the try block, the session begins the transaction and continues with the processes and finally commits it. If anything goes wrong, the try block throws an error and under the exception handling part, a rollback is issued for the transaction. And finally, the session is closed. This is an efficient way of handling database transactions using Hibernate.
2: What are the core interfaces available in hibernate?
Answer:
The core interfaces available in hibernate are:
a) Session: used to store and retrieve the objects and they are not thread-safe
b) SessionFactory: one object being created per application
c) Criteria: used to provide a conditional search over resultset
d) Query: obtained by invoking createQuery() method of Session
e) Configuration: used to specify the hibernate mapping file’s location
f) Transaction: used to perform several database operations
3: What is SessionFactory? Is it thread-safe object?
Answer:
SessionFactory is an interface creating session instances. Threads servicing the client requests obtain the session instances from the SessionFactory. SessionFactory is created only once for each application. More than one thread can access the SessionFactory concurrently since it is thread-safe object.
4: How will you create SessionFactory object?
Answer:
SessionFactory object can be created using buildSessionfactory() method.
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
SessionFactory sf = new Configuration().configure().buildSessionFactory();
5: What is Session? Is it a thread safe object?
Answer:
Session is obtained from SessionFactory and not thread-safe, meaning that it cannot be shared between threads. It is a single unit of work with the database. To avoid creating multiple sessions, ThreadLocal can be used. Get current session from the ThreadLocal object using get(). If no sessions are available, get a new session from SessionFactory object using openSession() method and set it in ThreadLocal.
6: Explain about Criteria in hibernate.
Answer:
a) Criteria in hibernate are used to create dynamic queries to execute
b) Criteria instances are obtained from session object using createQuery() method
c) Criteria mycriteria = session1.createCriteria(Empl.class)
*****
Hibernate Configuration
7: How do you configure hibernate?
Answer:
Hibernate could be configured in the following methods:
a) Create hibernate configuration file hibernate.cfg.xml
to provide hibernate configuration properties
b) Create hibernate mapping file say emp.hbm.xml
to provide hibernate mapping details i.e., mapping tables and java objects
c) Configuration class uses these two files to create SessionFactory which in turn creates session instances
8: What are the important tags of hibernate configuration file (hibernate.cfg.xml)?
Answer:
The important tags of hibernate configuration file are:
...
a) DTD: doctype
b) Configuration of JDBC connection: driver class, url, username, password
c) Dialect: specify the type of sql to be generated
d) Size of Connection Pool
e) Specify hbm2ddl.auto: automatic generation of database schema
f) Map hbm.xml files: include Hibernate Mapping files
9: Why column attribute is required if the property name is date
?
Answer:
If the column attribute is not given hibernate will map the column -name as the property name. However if date
is given as property name, column should be explicitly given since date is a keyword.
created_date
/>
10: How will you get hibernate statistics?
Answer:
Hibernate statistics could be obtained by:
a) using getStatistics() method of SessionFactory
b) SessionFactory.getStatistics();
11: How will you make generated sql to be displayed in console?
Answer:
Generated sql could be displayed in console by setting show_sql
property to true
in the hibernate configuration file.
12: How are the columns of the database mapped with the java class properties in hibernate?
Answer:
The columns of the database are mapped with the java class properties in hibernate as follows:
a) Write POJO (getters and setters) class
b) Create hibernate mapping file hibernate.cfg.xml
where mapping between table columns and the class properties are specified
empl_tabl
>
empl_name
>
empl_age
/>
all
column=dept_Id
/>
13: If you want to insert data for few columns into a large table with hundreds of columns, hibernate will generate the insert sql query at run time containing all the table columns which will create performance issue. How will you make the hibernate to generate dynamically generated sql queries containing only the necessary columns? For instance, it should not include the null columns / property values.
Answer:
We can make the hibernate to generate dynamically generated sql queries using dynamic-insert=true
attribute in the class mapping. Default option is false
.
UserDetails
catalog=ks
dynamic-insert=true
>
...
14: What is the flow of hibernate communication with database?
Answer:
The flow of hibernate communication with database is as follows:
a) First, load hibernate configuration file and create configuration object. Using configuration object load all hibernate mapping files.
b) Create SessionFactory from the Configuration object.
c) Create Session from the SessionFactory object.
d) Create the HQL query.
e) Run the query which retrieves list of java objects.
15: How will you configure Sequence generated primary key?
Answer:
We can configure sequence generated primary key by using
empId
type=java.lang.Long
>
myseq> emp_id_seq
16: How will you change one relational database to another database without code changes?
Answer:
We can change a relational database to another using hibernate SQL dialect. Hibernate will generate sql queries based on the dialect defined in the configuration file.
17: What is dynamic-insert and dynamic-update option in the class mapping?
Answer:
Dynamic-insert and dynamic-update option in the class-mapping are:
a) dynamic-insert=true/false
: Used to decide whether to include the columns having null properties, in the dynamically generated sql INSERT statement
b) dynamic-update=true/false
: Used to decide whether to include the null columns, in the dynamically generated sql UPDATE statement
18: How will you configure Hibernate to access the instance variables directly without using setter method?
Answer:
We can configure hibernate to access the instance variables directly without using setter method as follows:
a) Using access=field
attribute in the
b) field
/>
19: What is Automatic Dirty checking in hibernate?
Answer:
Automatic Dirty checking in hibernate:
a) means that Hibernate persists the data (or updates the database) automatically if the state of the object is modified inside a transaction when the transaction is committed and the session is opened
b) means no need for explicit update statements
20: Write down a sample code for Automatic Dirty checking.
Answer:
Automatic Dirty checking Sample Code:
Session session1 = sessionFactory1.openSession();
Transaction tx1 = session1.beginTransaction();
User user = (User)session1.get(User.class, 5L);
user.setUname(Shobhana
);
tx1.commit(); //data is synchronized with database
session1.close();
21: How hibernate is database independent and what are the changes required?
Answer:
Hibernate is database independent as by changing the below properties, databases can be replaced without much changes.
org.hibernate.dialect.Oracle9Dialect
oracle.jdbc.driver.OracleDriver
22: How will you include hibernate mapping file in the hibernate configuration file?
Answer:
We can include hibernate mapping file in the hibernate configuration file using
*****
Criteria Queries
23: What are the ways in which object can be fetched from the database in hibernate?
Answer:
The ways in which object can be fetched from the database in hibernate are:
a) using Criteria API
b) using Standard SQL
c) using HQL
d) using identifier
24: What is the use of Restrictions class?
Answer:
Restrictions class is used to implement comparison operations in criteria query. Using add() method of criteria query object, Restrictions can be added to the criteria query.
Criteria mycriteria = session1.createCriteria(Student.class);
mycriteria.add ( Restrictions.eq(age
, 18) );
25: How will you write criteria query to retrieve records having dept_name containing hr
and emp_salary between 20000 and 30000?
Answer:
The required criteria query can be written as follows:
List Employees = session1.createCriteria(Empl.class)
.add( Restrictions.like(dept_name
, hr%
) )
.add(Restrictions.between(emp_salary
, 20000, 30000) )
.list();
26: How will you sort the employee class in descending order by employee salary using Criteria query?
Answer:
The employee class can be sorted in descending order by employee salary using Criteria query using org.hibernate.criterion.Order class of Criteria API.
Criteria mycriteria = session1.createCriteria(Empl.class);
mycriteria.addOrder(Order.desc ( emp_salary
));
27: How will you find out the maximum salary from Employee class?
Answer:
The maximum salary from employee class can be found using org.hibernate.criterion.Projections class which is used to fetch minimum, maximum, average, distinct count of the property values.
Criteria mycriteria = session1.createCriteria(Empl.class);
mycriteria.setProjection ( Projections.max(emp_salary
) );
28: What are the methods available in Projections class?
Answer:
The methods available in Projections class are:
a) Projections.rowCount(): to fetch total row count of property values
b) Projections.countDistinct(): to fetch distinct count
c) Projections.avg(): to fetch average value
d) Projections.max(): to fetch maximum value
e) Projections.min(): to fetch minimum value
f) Projections.sum(): to fetch sum of property values
29: How will you implement pagination using criteria query?
Answer:
We could implement pagination using setFirstResults() and setMaxResults() methods. For instance, fetching records, starting from 20th record and retrieve the next 40 records from the database.
Criteria mycriteria = session1.createCriteria(Empl.class);
mycriteria.setMaxResults(20);
mycriteria.setFirstResult(40);
30: What are the disadvantages of Criteria query?
Answer:
The disadvantages of Criteria query are:
a) Performance issue: No control over hibernate generated query. If the generated query is slow, it will be difficult to tune the query.
b) Maintenance issue: Sql queries are written or scattered in java code. If any issues, we need to find out the problematic query in the application. Named queries which are stored in the hibernate mapping file are the best choice.
31: How is the Primary Key created using Hibernate?
Answer:
The primary key in Hibernate is created using
..
>
java.lang.String
>
20
/>
32: How do you create hibernate generated Primary Key?
Answer:
Hibernate generated Primary Key is created using
..
>
java.lang.Integer
>