-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewInventory.java
More file actions
49 lines (40 loc) · 1.5 KB
/
ViewInventory.java
File metadata and controls
49 lines (40 loc) · 1.5 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.List;
import java.util.Scanner;
import org.example.beans.Inventory;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
@SuppressWarnings("deprecation")
public class ViewInventory
{
public static void viewInventoryDetails()
{
Configuration cfg = new Configuration();
cfg.configure("resources/hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
/*
* Configuration and SessionFactory is responsible for create the table
*/
Session s = sf.openSession();
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("Enter The Product Id For Inventory View");
int id= sc.nextInt();
Criteria criteria = s.createCriteria(Inventory.class);
//Criteria fixed for showing all the product list using loop
@SuppressWarnings("unchecked")
List<Inventory> list=criteria.list();
for(Inventory stu:list)
{
if(id==stu.getId())
{
System.out.println("=========================================================================");
System.out.println(stu.getId()+" | "+stu.getName()+" | "+stu.getType()+" | "+stu.getQuantity()+" | "+stu.getPrice());
}
}
System.out.println("=========================================================================");
s.beginTransaction().commit();
}
}