私は次のプロジェクトとその "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>
だから私が得る出力は次のようになります。
休止状態:Insuranc1_0_、insurance0_としてinsurance0_.InsuranceNameを選択します。 Investem2_0_0_、保険0_InvestmentDate Investem3_0_0_ Insurance Insurance__保険金額_保険金額=から?
nullの場合
解決策をご提案ください。
おかげ
スネハ
yeaj ..私はそのキャッチを持っています、それはそこに行くだけです。しかし、なぜ私はテーブルにレコードを持っているときにそのエラーを投げているのですか? – Smitha
ID列のマッピングが間違っている可能性がありますか?たぶんDBでタイプが長くないのでしょうか? DDLとデータベースレコードをダンプできますか? –