2014-10-28 58 views
0

我想设置'水平'与一些值,但我收到异常。以下是版本和代码。net.sf.hibernate.PropertyValueException:非空属性引用空或瞬态值

Hibernate的版本:2.1

服务器:Weblogic的11克

映射文件:

<property name="Level" type="java.lang.Integer"> 
<meta attribute="default-value">new java.lang.Integer(0)</meta>  
<column name="Level" not-null="true" length="3" />  
</property> 

代码:

public Pol fillPol(ResultSet rs) throws SQLException { 
     Pol p = new Pol(); 
     p.setLevel(new Integer(rs.getInt("setLevel"))); 
     if (rs.IsNull()) { 
      p.setLevel(null); 
     } 
     return p; 
    } 

例外,我得到

Caused by: net.sf.hibernate.PropertyValueException: not-null property references a null or transient value 

请帮忙。

+0

还有你的代码无关与Hibernate。您在问题中使用简单的ResultSet。 – WeMakeSoftware 2014-10-28 08:37:47

回答

0

这是因为您有一个DB < - > Java数据类型不匹配。

要解决这个检查:

  • 数据库列。如果它允许有空值。
  • Java类型。如果它是 原始类型或没有。

尝试以下操作:

public Pol fillPol(ResultSet rs) throws SQLException { 
     Pol p = new Pol(); 
     p.setLevel(new Integer(rs.getInt("setLevel"))); 
     if (rs.IsNull()) { 
      p.setLevel(Integer.valueOf(0)); //according to the mapping you're not setting it to null, but to zero. 
     } 
     return p; 
    } 
+0

我们可以使用OC4j服务器正常工作,但weblogic正在给出异常 – Nisha 2014-10-28 08:17:52

+0

您有相同的数据库吗? – WeMakeSoftware 2014-10-28 08:33:59

+0

是的。有相同的DB – Nisha 2014-10-28 09:16:52

相关问题