У меня есть следующий проект и он возвращает "null". Как его решить?
Мой класс Java:
public class UpdateExample {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session sess = null;
try {
SessionFactory fact = new Configuration().configure().buildSessionFactory();
sess = fact.openSession();
Transaction tr = sess.beginTransaction();
Insurance ins = (Insurance)sess.get(Insurance.class, new Long(1));
ins.setInsuranceName(2);
ins.setInvestementAmount(20000);
ins.setInvestementDate(new Date());
sess.update(ins);
tr.commit();
sess.close();
System.out.println("Update successfully!");
}
catch(Exception e){
System.out.println("If null " + e.getMessage());
}
}
}
public class Insurance {
private long insuranceName;
private double investementAmount;
private Date investementDate;
public long getInsuranceName() {
return insuranceName;
}
public void setInsuranceName(long insuranceName) {
this.insuranceName = insuranceName;
}
public double getInvestementAmount() {
return investementAmount;
}
public void setInvestementAmount(double investementAmount) {
this.investementAmount = investementAmount;
}
public Date getInvestementDate() {
return investementDate;
}
public void setInvestementDate(Date investementDate) {
this.investementDate = investementDate;
}
}
insurance.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Insurance" table="Insurance">
<id name="insuranceName" type="long" column="InsuranceName">
<generator class="assigned" />
</id>
<property name="investementAmount">
<column name="InvestementAmount" />
</property>
<property name="investementDate">
<column name="InvestementDate" />
</property>
</class>
</hibernate-mapping>
Таким образом, я получаю вывод:
Hibernate: выберитеinsurance0_.InsuranceName as Insuranc1_0_, insurance0_.InvestementAmount as Investem2_0_0_, insurance0_.InvestementDate as Investem3_0_0_ из Insurance insurance0_, где insurance0_.InsuranceName =?
Если значение равно NULL
Пожалуйста, предложите решение, которое является нулевым
Спасибо
Снеха