package com.employee;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
@Table(name ="Employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence")
@SequenceGenerator(name = "sequence", sequenceName = "seq1", allocationSize = 1)
@Column(name = "SYS_I")
private Integer id;
@Column(name = "emp_id")
private String empId;
@Column(name = "emp_name")
private String empName;
@Column(name = "branch")
private String emp_branch;
@Column(name = "course")
private String course;
@Column(name = "head")
private String head;
}
package com.employeebranch;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
@Table(name ="EmployeeBranch")
public class EmployeeBranch {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "branchSequence")
@SequenceGenerator(name = "branchSequence", sequenceName = "bran_seq1", allocationSize = 1)
@Column(name = "SYS_I")
private Integer id;
@Column(name = "emp_branch")
private String emp_branch;
@Column(name = "emp_course")
private String course;
@Column(name = "emp_head")
private String empHead;
}enter image description here
Can anyone show how i can map fields using anotations like @OneToOne or @OneToMany or @ManyToOne. What kind of relationship it is in this condition?
So now here in emplpoyee branch table the value are like below. id emp_branch emp_course emp_head 1 mechanical physics Principal 2 mechanical chemistry Headmaster 3 electrical physics Principal 4 electrical chemistry Headmaster
and in employee table the values are like below. id emp_id emp_name branch course head 1 10 sachin mechanical physics 001 4 12 Yuvraaj mechanical chemistry 002enter image description here
select e.*, b.emp_head from EmployeeBranch b , Employee e where e.branch=b.emp_branch
and e.course = b.emp_course and e.branch = 'mechanical';
I want to set this resultant results in Employee entity using createQuery. How can i achecive this?
Note: I want only with using criteria or createQuery by mapping onetomany or onetoone or manytoone. I am confused when data is of above type. i dont want using JPA repository or HQL or Native query