0% found this document useful (0 votes)
52 views7 pages

Questions On Hibernate Spring Framework and Springboot Frame Work

The document contains a comprehensive set of questions and answers covering Hibernate, Spring Framework, and Spring Boot, organized into sections including Basics, Core Concepts, Annotations & Relationships, Transactions & Querying, Performance & Caching, and Advanced topics. Key concepts include ORM, Dependency Injection, Spring MVC, REST APIs, and Spring Boot features like auto-configuration and Actuator. It serves as a study guide for understanding essential aspects of these frameworks.

Uploaded by

schaayiii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views7 pages

Questions On Hibernate Spring Framework and Springboot Frame Work

The document contains a comprehensive set of questions and answers covering Hibernate, Spring Framework, and Spring Boot, organized into sections including Basics, Core Concepts, Annotations & Relationships, Transactions & Querying, Performance & Caching, and Advanced topics. Key concepts include ORM, Dependency Injection, Spring MVC, REST APIs, and Spring Boot features like auto-configuration and Actuator. It serves as a study guide for understanding essential aspects of these frameworks.

Uploaded by

schaayiii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

1: Hibernate (30 Questions)

Basics

1. What is Hibernate?
→ ORM (Object-Relational Mapping) tool that maps Java objects to database
tables.

2. What are the advantages of Hibernate over JDBC?


→ Less boilerplate code, automatic SQL generation, caching(every time hit is not
Required), lazy loading(store data when required), portability(database
independent).

3. Explain ORM.
→ Technique to map Java objects (classes) to database tables.

4. What is the difference between Hibernate and JPA?


→ JPA is a specification; Hibernate is an implementation.

5. What is the Hibernate configuration file?


→ [Link] or [Link] contains DB connection + Hibernate
settings.

-----------------------------------------------------------------------------------
------------

Core Concepts

6. What is SessionFactory in Hibernate?


→ Heavy weight object that provides Session instances; created once per
application.

7. What is Session in Hibernate?


→ Lightweight object representing a single unit of work with DB.

8. Explain the difference between Session and SessionFactory.


→ SessionFactory is created once; Session is created per request/transaction.

9. What are Hibernate mappings?


→ Ways to map Java classes to DB tables (@Entity, @Table, @Column).

10. What is lazy loading in Hibernate?


→ Fetches data only when needed, not immediately.

-----------------------------------------------------------------------------------
------------

Annotations & Relationships

11. What are the common Hibernate annotations?


→ @Entity, @Table, @Id, @GeneratedValue, @OneToMany, @ManyToOne, etc.

12. Explain @OneToMany vs @ManyToOne.


→ @OneToMany: One entity linked to many others.
@ManyToOne: Many entities linked to one parent.

13. What is @JoinColumn?


→ Defines the foreign key column.

14. What is @Embeddable and @Embedded?


→ Used for composite fields (value objects inside entities).

15. What is cascade in Hibernate?


→ Defines how operations (persist, delete, merge) are propagated to child
entities.

-----------------------------------------------------------------------------------
------------

Transactions & Querying

16. How does Hibernate handle transactions?


→ Using Transaction API or declarative Spring-managed transactions.

17. What is HQL?


→ Hibernate Query Language, object-oriented query language similar to SQL.

18. Difference between HQL and SQL?


→ HQL works with entity objects, SQL works with DB tables.

19. What is Criteria API in Hibernate?


→ Type-safe, programmatic way to create queries.

20. How do you write a named query in Hibernate?


→ Using @NamedQuery annotation or [Link].

-----------------------------------------------------------------------------------
------------

Performance & Caching

21. What is caching in Hibernate?


→ Storing frequently used data in memory to reduce DB hits.

22. Types of caching in Hibernate?


→ First-level (Session), Second-level (SessionFactory), Query cache.

23. What is difference between first-level and second-level cache?


→ First-level is session-scoped; second-level is application-wide.

24. Explain dirty checking in Hibernate.


→ Automatically detects changes in entity objects and updates DB.

25. What is n+1 query problem in Hibernate?


→ Excessive DB queries due to lazy loading. Solved by fetch join.

-----------------------------------------------------------------------------------
------------

Advanced

26. How does Hibernate manage primary keys?


→ @GeneratedValue(strategy = [Link]/IDENTITY/SEQUENCE/TABLE)

27. What is optimistic vs pessimistic locking?


→ Optimistic: Multiple users can read, conflicts resolved at update.
Pessimistic: Locks row immediately when reading.

28. What is the difference between merge() and update()?


→ update(): Reattaches a detached entity.
merge(): Copies values from detached to persistent.

29. What are transient, persistent, and detached states?


→ Transient: Not in DB.
Persistent: Associated with session.
Detached: Previously persistent but session closed.

30. How to improve Hibernate performance?


→ Use caching, batch fetching, proper fetch strategies, indexes.

-----------------------------------------------------------------------------------
------------

2: Spring Framework (30 Questions)

Basics

1. What is Spring Framework?


→ Lightweight, modular Java framework for enterprise applications.

2. What are the core features of Spring?


→ IoC, AOP, MVC, Transaction management, Data Access.

3. What is Dependency Injection (DI)?


→ Process of injecting dependencies into objects instead of hardcoding.

4. Explain Inversion of Control (IoC).


→ Delegating object creation to the Spring container.

5. What are the advantages of Spring?


→ Loose coupling, modularity, testability, integration.

-----------------------------------------------------------------------------------
------------

IoC & Beans

6. What is ApplicationContext in Spring?


→ Central interface for configuring Spring app (bean factory + more features).

7. What is a Spring Bean?


→ Object managed by Spring IoC container.

8. Different scopes of Spring Beans?


→ Singleton, Prototype, Request, Session, Application.

9. How are beans defined in Spring?


→ XML, annotations (@Component, @Bean), or Java config.

10. What is @Autowired?


→ Annotation for automatic dependency injection.

-----------------------------------------------------------------------------------
------------
AOP (Aspect-Oriented Programming)

11. What is AOP in Spring?


→ Allows separation of cross-cutting concerns like logging, security.

12. What are AOP concepts?


→ Aspect, JoinPoint, Advice, Pointcut, Weaving.

13. Difference between @Component, @Service, @Repository, @Controller?


→ All are stereotypes, but each has a semantic meaning for layered
architecture.

14. What is @Qualifier in Spring?


→ Used to resolve ambiguity when multiple beans of same type exist.

15. What is @Primary in Spring?


→ Marks a bean as the default choice when multiple beans match.

-----------------------------------------------------------------------------------
------------

Transactions & Data

16. What is Spring Transaction Management?


→ Declarative or programmatic management of transactions.

17. What is @Transactional?


→ Declares a method/class should run inside a transaction.

18. Difference between programmatic and declarative transaction management?


→ Programmatic: Explicit code.
Declarative: Using annotations/XML.

19. What is JdbcTemplate?


→ Utility class for simplifying JDBC operations.

20. Difference between checked and unchecked exceptions in Spring transactions?


→ Checked exceptions → rollback must be specified.
Unchecked exceptions → rollback by default.

-----------------------------------------------------------------------------------
------------

Spring MVC

21. What is DispatcherServlet in Spring MVC?


→ Front controller that handles all HTTP requests.

22. Explain Model, View, Controller in Spring MVC.


→ Model: Data, View: UI, Controller: Handles logic/requests.

23. What is @RequestMapping?


→ Maps URLs to controller methods.

24. Difference between @Controller and @RestController?


→ @Controller returns view, @RestController returns JSON/XML.

25. What is HandlerInterceptor in Spring MVC?


→ Intercepts requests for logging, authentication, etc.
-----------------------------------------------------------------------------------
------------

Advanced

26. What are Spring profiles?


→ Used to group beans/configs for different environments (dev, prod).

27. What is Spring Security?


→ Provides authentication, authorization, CSRF, etc.

28. Difference between Spring and Spring Boot?


→ Spring Boot simplifies setup with auto-config, embedded servers, starters.

29. What is Spring Data JPA?


→ Abstraction layer over JPA for easy CRUD repository management.

30. What is the role of ApplicationContextAware?


→ Gives access to ApplicationContext inside a bean.

-----------------------------------------------------------------------------------
------------

3: Spring Boot (30 Questions)

Basics

1. What is Spring Boot?


→ Extension of Spring framework to simplify configuration and deployment.

2. Advantages of Spring Boot?


→ Auto-configuration, embedded server, starters, Actuator, reduced boilerplate.

3. What are Spring Boot starters?


→ Predefined dependencies (e.g., spring-boot-starter-web, spring-boot-starter-
data-jpa).

4. What is Spring Boot auto-configuration?


→ Automatically configures beans based on classpath and settings.

5. What are Spring Boot properties files?


→ [Link] / [Link] for configuration.

-----------------------------------------------------------------------------------
------------

REST & Web

6. How do you create a REST API in Spring Boot?


→ Use @RestController, @RequestMapping.

7. What is @PathVariable vs @RequestParam?


→ @PathVariable: of URL, @RequestParam: query parameter.

8. What is ResponseEntity?
→ Represents HTTP response (status, headers, body).

9. What is @CrossOrigin in Spring Boot?


→ Enables CORS for APIs.

10. Difference between GET, POST, PUT, DELETE in REST?


→ CRUD mapping: GET=Read, POST=Create, PUT=Update, DELETE=Delete.

-----------------------------------------------------------------------------------
------------

Data & JPA

11. What is CrudRepository in Spring Boot?


→ Interface with CRUD methods for entities.

12. Difference between CrudRepository, JpaRepository, PagingAndSortingRepository?


→ JpaRepository adds pagination, batch methods.

13. How does Spring Boot connect to DB?


→ Auto-config using [Link], [Link].

14. What is @Entity in Spring Boot?


→ Marks a class as a JPA entity.

15. How does Spring Boot handle transactions?


→ With @Transactional.

-----------------------------------------------------------------------------------
------------

Security & Actuator

16. What is Spring Boot Actuator?


→ Provides endpoints for monitoring (health, metrics, info).

17. What is Spring Boot DevTools?


→ Automatic restart and live reload for development.

18. What is Spring Security in Boot?


→ Provides authentication and authorization support.

19. How to secure a REST API in Boot?


→ Using Spring Security, JWT, or OAuth2.

20. What is JWT and how does Boot support it?


→ JSON Web Token for stateless authentication.

-----------------------------------------------------------------------------------
------------

Deployment & Advanced

21. How does Spring Boot run without a [Link]?


→ Uses embedded Tomcat/Jetty server.

22. How do you change the default server port in Spring Boot?
→ [Link]=8081 in [Link].

23. What is difference between WAR and JAR deployment in Spring Boot?
→ JAR = standalone, WAR = deployable to external server.
24. How do you handle exceptions in Spring Boot?
→ @ControllerAdvice + @ExceptionHandler.

25. What are Spring Boot profiles?


→ Environment-specific configurations ([Link], application-
[Link]).

26. How do you schedule tasks in Spring Boot?


→ Using @EnableScheduling + @Scheduled.

27. How do you use externalized configuration in Boot?


→ Use [Link] or @Value.

28. What is Spring Boot CLI?


→ Command-line tool to quickly bootstrap Boot apps.

29. What is Spring Cloud in relation to Boot?


→ For microservices (config server, service discovery, load balancing).

30. How do you monitor Spring Boot applications?


→ Using Actuator + Micrometer + Prometheus/Grafana.

-----------------------------------------------------------------------------------
------------

You might also like