I have a problem with Hibernate @EmbeddedId.
@Embeddable
public class EnrolRegEmbededId implements Serializable
{
@Column(name="ENROL_NO")
private String enrolNo;
@Column(name="REG_NO")
private String regNo;
}
@Entity
@Table(name = "PTAX_ENROL_REG_PRINCIPAL_INFO")
public class Enrol_reg_principal_info implements Serializable {
@EmbeddedId
private EnrolRegEmbededId enrolReg;
@Column(name = "APPLN_TYPE")
private String type;
@Column(name = "FIRST_NM")
private String f_name;
@Column(name = "MIDDLE_NM")
private String m_name;
@Column(name = "LAST_NM")
}
I get data from class Enrol_reg_principal_info
when both enrolNo and regNo have a value.
Why do I get NUllPointerException when either enrolNo or regNo have no value?
String hql = " from Enrol_reg_principal_info prin where prin.enrolReg.regNo=:id";
to get a value for regNo;
String hql = " from Enrol_reg_principal_info prin where prin.enrolReg.enrolNo=:ec";
to get a value for enrolNO.
public EnrolRegPrinModel masterDetailsEC(String EC) throws Exception {
EnrolRegPrinModel ecDetails = new EnrolRegPrinModel();
Enrol_reg_principal_info info = new Enrol_reg_principal_info();
Session s = null;
try {
s = sessionFactory.openSession();
String hql = " from Enrol_reg_principal_info prin where
prin.enrolReg.enrolNo=:ec";
Query q = s.createQuery(hql);
q.setString("ec", EC);
info = (Enrol_reg_principal_info) q.uniqueResult();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return ecDetails;
}