Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Open up your MySQL database interface using your preferred method. 2 . Create a database called lab 7 db , it will contain

1. Open up your MySQL database interface using your preferred method.
2. Create a database called lab7db, it will contain one table called students (Fields
are: id (varchar 20, and primary key), firstname (varchar 50), lastname
(varchar 50), and email (varchar 50)).
3. Truncate the database table to ensure it is empty.
4. Download the hibernate-release-5.4.18.Final.zip or the hibernate-release-
5.4.18.Final.rar file, from the Lab Support folder available through the Google
Classroom
5. Create a new project entitled HibernateLab7.
6. Extract all files from the hibernate-release-5.4.18.Final.zip file, and add all jars
to your projects Classpath, following the SETUP HIBERNATE 5.4.18
PROJECT tutorial, available in the Google Classroom, if you havent already
done so.
7. Create a new package called factories.
8. Create a new class called SessionFactoryBuilder inside the factories package.
9. Inside the SessionFactoryBuilder create a private static attribute of type
SessionFactory (org.hibernate.SessionFactory) and two public static methods
called getSessionFactory (accepts no parameters and returns a
SessionFactory); and closeSessionFactory (accepts no parameters and
returns nothing).
10. Complete the getSessionFactory method by first checking if the SessionFactory
attribute is null, if it is, then instantiate it using the following statement: new
Configuration().configure("hibernate.cfg.xml").addAnnotatedClass
(Student.class).buildSessionFactory();
(org.hibernate.cfg.Configuration). Complete the method by returning the
factory object.
11. Complete the closeSessionFactory method by checking if the SessionFactory
attribute is not null, if it is, then using the attribute, call its close method.
12. Inside the src folder create a new XML file and call it hibernate.cfg.xml. In
Eclipse Right Click on the Projects src folder -> New -> Other -> XML folder -
> XML File -> Next -> name the file as indicated above -> Finish.
Please view the image of an hibernate.cfg.xml file at the end of this document
for the exact contents. The contents of the file were explained in the lecture
session.
13. Create a new package called models.
14. Create a new class called Student inside the models package, with four private
attributes: id, first name, last name and email.
15. Create a default constructor, primary constructor, accessors, mutators and
toString methods for the Student class.
16. Add the methods (and contents) seen in the image below to your Student class.
Similar methods were explained to you in the lecture session.
17. Annotate/Add annotations to the attributes of the Student class, to map them to
the database table columns. This was explained to you in the lecture session.
Prepared by:- Christopher Panther | November 4,2020. Page 4 of 5
Updated: March 11,2022
DO NOT include the following in your annotations:
This is only needed for primary keys that are autogenerated, and may cause a
problem when sending data to the database server.
18. Create a main package.
19. Create a driver class inside the main package with a main method. Inside the
main method instantiate your Student class and call the following public
methods in the stated order: create, readAll, update, readAll, delete, readAll.
After calling the methods call the closeSessionFactory method from the
SessionFactoryBuilder class.
NB** You will need to use the Scanner class to accept user input for student
creation, update and delete. Only update and delete a user that you know exists.
Please use to foreach loop when iterating over the List object and display each
individual student.
20.Run your application.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago