Saturday, 12 March 2016

Creating Entity classes for tables which do not have any primary key in Hibernate

Create a class with composite keys

@Embeddable
public class ClassificationPK implements Serializable {
    @Column(name="EMPLOYEE_NAME")
private String username;
@Column(name="EMPLOYEE_PHONE_NUMBER")
private String userDet;
}


@Entity
@Table(name="EMPLOYEE", schema="employee_detail")
@NamedQuery(name="Employee.findAll", query="SELECT i FROM Employee i")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;

@Column(name="EMPLOYEE_NAME" , insertable=false, updateble=false)
private String userName;

@Column(name="EMPLOYEE_DETAILS")
private String userDet;

@Column(name="EMPLOYEE_PHONE_NUMBER" , insertable=false, updateble=false)
private String userDet;

}

No comments:

Post a Comment