-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateInventory.java
More file actions
49 lines (44 loc) · 1.47 KB
/
UpdateInventory.java
File metadata and controls
49 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package entities;
import java.util.Scanner;
import org.example.beans.Inventory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class UpdateInventory
{
public static void updateInventoryDetails()
{
/*
* Configuration and SessionFactory is responsible for create the table
*/
Inventory st = new Inventory();
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("Enter the ID for Update the Product Details");
//@SuppressWarnings("unused")
int id= sc.nextInt();
System.out.println("Enter Updated Product Name");
String name = sc.next();
sc.nextLine();
System.out.println("Enter Updated Product Type");
String type = sc.nextLine();
System.out.println("Enter Updated Product Quantity");
int quantity= sc.nextInt();
sc.nextLine();
System.out.println("Enter Updated Product Price");
int price= sc.nextInt();
sc.nextLine();
//updated all the Inventory product list by using porimry key (id).
Configuration cfg = new Configuration();
cfg.configure("resources/hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
st.setId(id);
st.setName(name);
st.setType(type);
st.setQuantity(quantity);
st.setPrice(price);
s.update(st);
s.beginTransaction().commit();
}
}