0% found this document useful (0 votes)
0 views

Day06 - Hibernate Application Development & CRUD Operations.pptx

The document outlines the development of a Student Management System using JavaFX and Hibernate, focusing on implementing CRUD operations for data management. It details the setup of JavaFX in Eclipse, the use of Scene Builder for UI design, and the creation of a repository and service layer for data access. Additionally, it emphasizes the importance of user interface design and error handling to improve user experience.

Uploaded by

anh2251220096
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Day06 - Hibernate Application Development & CRUD Operations.pptx

The document outlines the development of a Student Management System using JavaFX and Hibernate, focusing on implementing CRUD operations for data management. It details the setup of JavaFX in Eclipse, the use of Scene Builder for UI design, and the creation of a repository and service layer for data access. Additionally, it emphasizes the importance of user interface design and error handling to improve user experience.

Uploaded by

anh2251220096
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Hibernate Application Development &

CRUD Operations
Objectives
◆ Data Management
▪ Implement CRUD (Create, Read, Update, Delete) operations to manage data
effectively.
▪ Utilize Hibernate to map Java objects to database tables, simplifying data
persistence and retrieval.
◆ User Interface Development
▪ Design and develop a user-friendly interface using JavaFX, enabling
seamless interaction with the application.
▪ Implement features such as form input validation, error handling, and
feedback mechanisms to enhance user experience.

2
Student Management System
Build Simple Student Management System
◆ Step 1. Setup JavaFX in Eclipse
◆ Step 2. Setup Scene Builder
◆ Step 3. Build CRUD Application with Repository Pattern
◆ Step 4. Design GUI Application with JavaFX

3
Setup JavaFX in Eclipse IDE
How to Set Up JavaFX with OpenJFX in Eclipse
◆ Step 1. Download OpenJFX : Obtain the OpenJFX libraries from Gluon or
include them as dependencies in your Maven or Gradle project.
◆ Step 2. Configure Eclipse:
▪ Add the OpenJFX libraries to your project's build path.
▪ Set the VM arguments to include the path to the OpenJFX libraries.
▪ Install the e(fx)clipse plugin (optional) for enhanced JavaFX development support.

5
1. Open Eclipse, Help | Eclipse Market | e(fx)clipse
◆ e(fx)clipse is a set of plugins who make developing JavaFX 2 application. It provides wizards,
specialized CSS and XML editors needed for JavaFX usage of CSS and XML.

6
What is Gloun ?
◆ Gluon is a company dedicated to supporting and advancing JavaFX
development. They play a crucial role in the JavaFX ecosystem by providing
various tools, services, and resources for developers.
◆ Gluon provides various tools and IDE plugins to enhance JavaFX
development, such as:
▪ Scene Builder: A visual tool for designing JavaFX user interfaces.
▪ Gluon Plugin for IntelliJ IDEA: Provides support for Gluon Substrate and Gluon Mobil
e development within IntelliJ IDEA.

7
2. Open openfx.io page, download JavaFX
◆ Obtain the OpenJFX libraries from Gluon

8
3. Download JavaFX
◆ Download JavaFX SDK with version 21.0.2 [LTS]

9
4. Open Eclipse, Window | Preferences | Java | Build Path | User Library

Add the OpenJFX libraries to your project's build path

10
5. Extract JavaFX SDK, Add External JARs | Browser to JavaFX SDK lib

11
Setup Scene Builder
What is Scene Builder ?
◆ Scene Builder is a powerful and intuitive visual tool designed specifically for creating user
interfaces (UIs) for JavaFX applications. It allows developers to design UIs without writi
ng code, using a drag-and-drop interface and a wide range of pre-built UI components.
◆ Key Features of Scene Builder:
▪ Visual Layout: Drag and drop UI components onto a canvas to create your desired layout.
▪ Component Library: Access a comprehensive library of standard JavaFX UI controls, including butt
ons, text fields, labels, menus, charts, and more.
▪ Properties Editor: Customize the properties of each UI component, such as size, color, font.
▪ FXML Generation: Scene Builder automatically generates FXML code, which is a declarative XML-b
ased language for describing JavaFX UIs.

13
1. Open Eclipse, File | New | Maven Project

14
2. Open Gluon Scene Builder

15
3. Open JavaFX File

16
Build CRUD Application with
Repository Pattern
1. Open Eclipse, File | New | Maven Project
Create Project using Maven

18
2. Check Create a simple project -> Browse Project -> Next
Check the checkbox to avoid using the available template project.

19
3. Fill the information Project -> Click Finish

20
4. Structure of Maven Project

Lists the external libraries and


modules that the project relies on.

21
5. Create hibernate.cfg.xml in package resources
Create Session-Factory to connect to MSSQL using Hibernate

22
What is Pojo?
◆ POJO stands for Plain Old Java Object. It's a term used to describe a simple Java object that doesn't
rely on any specific framework or library. In other words, it's a regular Java class that follows basic
object-oriented principles without any special constraints or dependencies.
◆ Benefits of Using POJOs:
▪ Simplicity and Flexibility: POJOs are easy to understand, create, and maintain due to their straight
forward structure.
▪ Reusability: POJOs can be reused across different parts of an application or even in different
applications.
▪ Testability: POJOs are easy to unit test because they don't have external dependencies.
▪ Loose Coupling: POJOs promote loose coupling between different parts of an application, making it
easier to modify or replace components.

23
6. Create Books in Pojo Package
Create a Book POJO and configure it for automatic table mapping in the database.

24
7. Create Students in Pojo

25
What is DAO Layer?
◆ DAO stands for Data Access Object. It's a design pattern used to abstract and encapsulate the
logic for accessing data from a data source, such as a database, file system, or web service. The
DAO pattern promotes loose coupling between the application's business logic and the underlying data
access mechanisms.
◆ Key Components of the DAO Pattern:
▪ DAO Interface: Defines the methods for accessing and manipulating data. This interface provides a clear separation
between the application's business logic and the specific data access implementation.
▪ DAO Implementation: Implements the DAO interface and contains the actual code for interacting with the data
source. This implementation can use JDBC, JPA, Hibernate, or any other data access technology.
▪ Entity Objects: Represent the data being accessed and manipulated. These objects typically correspond to tables
in a relational database or documents in a NoSQL database.

26
8. Create StudentDAO

27
9. Save Student in StudentDAO

28
10. Get All Student in StudentDAO

29
11. Delete Student in StudentDAO

30
12. Find A Student in StudentDAO

31
13. Update a Student in StudentDAO

32
What is Repository Layer?
◆ The term "repository" is often used in the context of data access and is closely related to the DAO
pattern.While there isn't a strict definition, a repository can be seen as an evolution
or specialization of the DAO pattern with some additional characteristics.
◆ Key Concepts of a Repository:
▪ Collection-like interface: Repositories often provide a collectionlike interface for accessing and managing
entities, similar to working with collections in Java. This makes the API more intuitive and user-friendly.
▪ Query methods: Repositories typically offer methods for querying data based on various criteria, such as
finding entities by ID, name, or other attributes.
▪ Persistence technology agnostic: Ideally, repositories should be independent of the underlying persistence
technology (e.g., JPA, Hibernate, JDBC). This allows for greater flexibility and portability.

33
14. Create IStudentRepository

34
15. Create StudentRepository

35
What is Service Layer?
◆ In software architecture, a Service represents a layer or component responsible for implementing the business
logic of an application. It acts as an intermediary between the presentation layer (user interface) and the data
access layer (repositories or DAOs).
◆ Responsibilities of a Service:
▪ Business Rules and Logic: Services encapsulate the core business rules and logic of the application.
They perform calculations, validations, and other operations that are specific to the domain.
▪ Transaction Management: Services often manage transactions to ensure data consistency and integrity.
They coordinate multiple data access operations within a single transaction.
▪ Orchestration: Services orchestrate the interactions between different components of the application, such as
repositories, external services, and other services.
▪ Data Transformation: Services may transform data between different formats or representations as needed by
the presentation layer or other components.

36
16. Create IStudentService

37
17. Create StudentService

38
18. Create Main Function

39
19. Result

40
20. Result

41
Design GUI Application with
JavaFX
1. Open Eclipse, File | New | JavaFX Project

43
2. Fill the Project Name

44
3. Add JavaFX to Project

45
5. Add JavaFX SDK to Project

46
6. Choose the application type
Create a AccountController in controller package

47
7. Build the Architecture
Build an MVC architecture because JavaFX often uses it

48
8. Open the page | copy VM arguments
Copy the VM argement to run the JavaFX Application

49
9. Right Click | Run Configurations…
Add VM Arguments to Java Project

50
10. Edit Main File
Set the default screen when the project starts

51
11. Run JavaFX Project

52
12. Add Reference Another Project

53
13. Open AccountGUI.fxml in SceneBuilder

54
14. Edit Account.fxml

55
15. Edit Account.fxml

56
16. Edit Account.fxml

57
17. Edit Account.fxml

58
18. Edit Account.fxml

59
19. Edit the AccountController.java

60
20. Edit the AccountController.java

61
21. Show all student and get StudentID when click first cell

62
22. CRUD for Students

63
23. Run Project

64
Summary
Concepts were introduced:
▪ Implement CRUD (Create, Read, Update, Delete) operations to manage data
effectively.
▪ Utilize Hibernate to map Java objects to database tables, simplifying data
persistence and retrieval.
▪ Design and develop a user-friendly interface using JavaFX, enabling
seamless interaction with the application.
▪ Implement features such as form input validation, error handling, and
feedback mechanisms to enhance user experience.

65

You might also like