8 - Spring Data JPA | Spring Boot | Project Work - Add Enquiry | Complex Form Using JPA Hibernate

preview_player
Показать описание
SOURCE CODE (GitHub Link)

PURPOSE:
This video covers Adding Enquiry. Its using advanced form handing approach and finally processing the form data using Spring Data JPA Hibernate internally with @Transactional approach.

Enquiry Entity is a major entity of this project and whole functionality is designed around this entity. Moremover this single form covers 7 entities : Enqury, EnquirySource, EnquiryCourse, Contact, Address, Institute and Course. The entity Followup is not used in this video.

This form uses EnquiryCommand object to bind form properties used in Thymeleaf Template page. I tried to reuse most of the Enquiry entity properties by wrapping Enquiry into EnquiryCommand using Has-A relation.

The form using reference data : Institute List, Courses and Enquiry Source.

Courses are loaded in form based on Institute Selection. Here jQuery AJAX call is used to fetch courses and fees for selected institute. The form has Committed Fees Option which is filled when user checks Courses using small JavaScript code.

The example covers Spring Data JPA Query Methods like findByName(String name), findById(Long id), "public List of Course findCourseListByInstitute_instituteId(Long instituteId)" etc. These inbuilt convention saves many lines of code. Thanks to Spring Data API which has automated such common use-cases.

What is Query Method: Query methods are methods that find information from the database and are declared on the repository interface. Its a unique feature of Spring Data JPA.

If you are not fan of Hibernate/JPA or Any such ORM technology. I suggest you please try Spring Data API its saves may lines of code and save cost. Also high productive technology.

Finally @Transaction is used to manage the data integrity as the form data is divided in multiple tables. If all okay then transaction is committed. Else transaction will be automatically rolled back. This Transaction is also a great feature offered by Spring Framework.

SOURCE CODE REFERENCE:
1. EnquiryController Mappings CODE:
@GetMapping("/")
public String index(Model m) {
}

@GetMapping("/save-enquiry")
return "redirect:/enq-list";
}


2. REFERENCE FORM CODE:
@ModelAttribute("instituteList")
public List of Institute getInstList() {
}

@ModelAttribute("sourceList")
public List of EnquirySource getSourceList() {
}

@GetMapping("/get-courses")
@ResponseBody
}
3. SAVE FORM HANDING CODE:
@Transactional
public void saveEnquiry(EnquiryCommand cmd) {

Date d = new Date();

EnquiryCourse ec = new EnquiryCourse();
}
}


TECHNOLOGY USED:
Java 8, Spring Boot, Spring Data JPA, MySQL Database, NetBeans IDE, Hibernate JPA Implementation, Maven, MySQL Workbench, JSON, MicroServices.

PREVIOUS VIDEO IN CASE YOU MISSED (Spring Data JPA | Spring Boot | Project Work - Course Save and List | Class & Map Projection) :

Doel -
Deze video behandelt het toevoegen van vragen. Het maakt gebruik van een geavanceerde formulierafhandeling en verwerkt uiteindelijk de formuliergegevens met Spring Data JPA Hibernate intern met @Transactional.
Рекомендации по теме
Комментарии
Автор

Another awesome video boy. I really liked and understood the concept in this one on when to use findById vs. getOne. I used to use findById everywhere but your explanation is awesome about when to use findById vs getOne repository method. Thanks a lot for this useful video. I am excited about the remaining 4 videos in this list :)

syednoman
Автор

Hey Vikram,
Great work! Thanks again for this series of tutorials. I was looking for example "JPA Save() to insert data into multiple tables". This is perfect example for that. But I didn't find it till I have gone through first 5 videos. I got it because I have decided to go through whole tutorial series. Not everyone does it, if you would improve the titles little bit it will be beneficial to both you and viewers. Please!

dattatrayatembare
Автор

when u did programming for eidt functionality at that time also y u didnt made use of ajax ?

myharsh
Автор

hello sir i got and error while getting courses by clicking on intitutes alot of jackson to resolve it ?

Zohan-v
Автор

Hello, There is just a small remark, you have to empty HTML element before loading. $("#id_courses").empty();

aallal
Автор

naah my page is not opening up, nor it is showing any error on the console.

myharsh
Автор

Please make video how to return nested json object from db

LifeDude
Автор

sir have u make registration, login ?

Zohan-v
Автор

hello sir i need enquiry.form html page

surajgupta
welcome to shbcf.ru