How should i store the data into the object and calling it by using the hashmap ?
means is : how should i get the data JPA extraction and call it at mymethod class ?
ListCustomer.put(Long.valueOf(1), new Customer("","","",""));
What I have tried:
SelectCustomer
private int SelectCustomer() {
String Query = "from Customer";
int result = 0;
sessionFactory = new Configuration().configure("hibcfg.glotng.xml")
.addAnnotatedClass(Customer.class).buildSessionFactory();
session = sessionFactory.getCurrentSession();
try {
session.beginTransaction();
theCustomer = session.createQuery(Query).list();
System.out.println("############ Customer #######################");
for(Iterator iterator = theCustomer.iterator();iterator.hasNext();){
Customer theCustomer = (Customer) iterator.next();
System.out.println(theCustomer.getName());
System.out.println(theCustomer.getIdNumber());
System.out.println(theCustomer.getBirthDate());
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
session.close();
sessionFactory.close();
return result;
}
}
model
package com.amlaPortal.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "customer")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long Id;
@Column(name = "name")
private String Name;
@Column(name = "id_number")
private String IdNumber;
@Column(name = "birth_date")
private String BirthDate;
@Column(name = "mobile_no")
private String MobileNo;
public Customer(){
}
public Customer(String name, String idNumber, String birthDate, String mobileNo) {
Name = name;
IdNumber = idNumber;
BirthDate = birthDate;
MobileNo = mobileNo;
}
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getIdNumber() {
return IdNumber;
}
public void setIdNumber(String idNumber) {
IdNumber = idNumber;
}
public String getBirthDate() {
return BirthDate;
}
public void setBirthDate(String birthDate) {
BirthDate = birthDate;
}
public String getMobileNo() {
return MobileNo;
}
public void setMobileNo(String mobileNo) {
MobileNo = mobileNo;
}
@Override
public String toString() {
return "Customer{" +
"Id=" + Id +
", Name='" + Name + '\'' +
", IdNumber='" + IdNumber + '\'' +
", BirthDate='" + BirthDate + '\'' +
", MobileNo='" + MobileNo + '\'' +
'}';
}
}
my method
package com.amlaPortal;
import com.amlaPortal.entity.Customer;
import com.amlaPortal.entity.TotalCount;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
class mymethodc {
List<Map<Long, Customer>> ListCustomer = new ArrayList<Map<Long,Customer>>();
public void myMap(){
ListCustomer.put(Long.valueOf(1), new Customer("","","",""));
}
}