Am new to Java Hibernate, using hibernate annotation to join and fetch the column from MySQL DB.I have two tables Order_headers table and Branch table.I have branch code in Order_headers table i have branch_code
,in branch table i have branch_code,branch_name,branch_desc. i want to combine Branch details table columns with order_headers table.
Order_headers.class
@Entity
@Table(name = "order_headers")
public class Order_headers {
@Column(name = "merchant_code")
private int merchant_code;
@Column(name = "device_id")
private String device_id;
@Id @GeneratedValue
@Column(name = "bill_number")
private int bill_number;
@Column(name = "order_number")
private String order_number;
@Column(name = "order_value")
private double order_value;
@Column(name = "payment_type")
private String payment_type;
@Column(name = "payment_status")
private String payment_status;
@Column(name = "order_datetime")
private Timestamp order_datetime;
//format YYYY-mm-dd
@Column(name = "order_date")
private String order_date;
//format HH:mm:ss
@Column(name = "order_time")
private String order_time;
@Column(name = "sub_total")
private double sub_total;
@Column(name = "VAT")
private double VAT;
@Column(name = "grand_total")
private double grand_total;
@Column(name = "branch_code")
private int branch_code;
@OneToOne(mappedBy = "order_headers", cascade=CascadeType.ALL)
@Fetch(FetchMode.JOIN)
private Branch branch;
@Column(name = "discount")
private double discount;
//Getter and setters
}
Branch
@Entity
@Table(name = "branch")
public class Branch {
@Id @GeneratedValue
@Column(name = "branch_code")
private int branch_code;
@Column(name = "branch_name")
private String branch_name;
@OneToOne
@JoinColumn(name = "branch_code")
private Order_headers order_headers;
//Getter and setters
}
Fetch Query
ArrayList<Order_headers> order_details = (ArrayList<Order_headers>) session.createQuery("FROM Order_headers").list();
It shows only data from order_headers table.Not able to get the data from Branch table.Help me to solve this issue.