Please have a look at the below code.
String textName=request.getParameter("textName");
String textadr1=request.getParameter("textadr1");
String textadr2=request.getParameter("textadr2");
String textcntry=request.getParameter("textcntry");
String textregNo=request.getParameter("textregNo");
AgentContact agentContact=new AgentContact();
AgentContact agentContact2=new AgentContact();
Agent agent=new Agent();
agent.setName(textName);
agent.setRegistrationNumber(textregNo);
agent.setDateOfDealStart(textDateDealing);
agent.setRegistrationDate(textregDate);
session.save(agent);
session.save(agentContact);
session.save(agentContact2);
session.getTransaction().commit();
In the above code, we get the values from a form, that is why request.getParameter() is used. However, user may or may not fill some fields like name, so the txtName will be empty.
However when this code is executed, I noticed Hibernate added "empty" string to these non specified Strings, instead of entering null. How can I set the code so it enters null values when the text are actually empty?
NULL