0% found this document useful (0 votes)
4 views4 pages

Java Spring & Hibernate Project Guide

The document outlines Experiment 9 for a Project-Based Learning course in Java, focusing on creating applications using Spring and Hibernate. It includes aims, objectives, implementation code for dependency injection, CRUD operations, and transaction management, along with learning outcomes. The experiment emphasizes understanding CRUD workflows, entity mapping, and Hibernate's session management.

Uploaded by

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

Java Spring & Hibernate Project Guide

The document outlines Experiment 9 for a Project-Based Learning course in Java, focusing on creating applications using Spring and Hibernate. It includes aims, objectives, implementation code for dependency injection, CRUD operations, and transaction management, along with learning outcomes. The experiment emphasizes understanding CRUD workflows, entity mapping, and Hibernate's session management.

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 9
Student Name: MD Shan E Islam UID: 23BCS10403
Branch: B.E CSE Section/Group:23BCS 605-B
Semester: 05 Date of Performance:03.11.25
Subject Name: Project-Based Learning in Java Subject Code: 23CSH-304

1. Aim: Create Java applications using Spring and Hibernate for dependency injection,
CRUD operations, and transaction management.

2. Objective:
• Demonstrating Dependency Injection (DI) using Spring s IoC container.
• Performing CRUD operations using Hibernate ORM.
• Implementing transaction management in a Spring Hibernate integrated application.

3. Implementation/Code:
a. import
[Link].*; class
Course {
String courseName; String duration;
Course(String n, String d){ courseName=n; duration=d; }
public String toString(){ return courseName+" ("+duration+")"; }
}
class Student {
String name; Course course;
Student(String n, Course c){ name=n; course=c; } void
display(){ [Link]("Student: "+name+", Course:
"+course); }
}
public class EasySpring {
public static void main(String[] args){
Course c = new Course("Java Full Stack", "6 months");
Student s = new Student("Zaka", c); // manual DI (simulating @Bean
injection)
[Link]();
}
}

Name: MD Shan E Islam UID: 23BCS10403


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Output:

b. Code: import [Link].*; class


Student {
int id; String name; int age;
Student(int i,String n,int a){id=i;name=n;age=a;}
public String toString(){return "ID:"+id+", Name:"+name+",
Age:"+age;}
} public class
HibernateSim {
public static void main(String[] args){
Map<Integer,Student> db = new HashMap<>();
[Link](1,new Student(1,"John",22));
[Link]("Insert Success!");
[Link]("Student List:");
[Link]().forEach([Link]::println);
[Link](1,new Student(1,"John Updated",23));
[Link]("After Update: "+[Link](1));
[Link](1);
[Link]("After Delete: "+[Link]()+" record(s)
left.");
}
}

Output:

Name: MD Shan E Islam UID: 23BCS10403


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

C.
import [Link].*; class
Account {
String id; int balance;
Account(String i,int b){id=i;balance=b;}
} public class BankTrans
{
static void transfer(Account a1, Account a2, int amt){
[Link]("Attempting ₹"+amt+" transfer from "+[Link]+"
to "+[Link]+"..."); if([Link]<amt){
[Link]("Transaction Failed: Insufficient balance
— rolled back!");
return; }
[Link]-=amt; [Link]+=amt;
[Link]("Transaction Successful: ₹"+amt+" transferred
from "+[Link]+" to "+[Link]);
}
public static void main(String[] args){
Account acc1=new Account("Acc101",500);
Account acc2=new Account("Acc102",1000);
transfer(acc1,acc2,300);
transfer(acc1,acc2,400); // should fail
}
}

Name: MD Shan E Islam UID: 23BCS10403


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

OUTPUT:

4. Learning Outcome:
• Understand CRUD (Create, Read, Update, Delete) workflow.
• Learn how entity mapping simulates database storage.
• Recognize how Hibernate manages session-like operations.

Name: MD Shan E Islam UID: 23BCS10403

You might also like