2011-08-20 68 views
0

這裏很簡單的問題......但我不能解決它。 我有一個簡單的類從我的模型休眠映射問題

public class Catalogazione extends ModelEntity { 

private String nome; 
private int showBox; 

public int getShowBox() { 
    return showBox; 
} 

public void setShowBox(int showBox) { 
} 

public String getNome() { 
    return nome; 
} 

public void setNome(String nome) { 
    this.nome = nome; 
} 
} 

注意ModelEntity已經定義了一個id屬性,整數爲好。 它映射到一個Oracle表與此映射文件:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > 
<hibernate-mapping> 
    <class name="alekso.npe.model.Catalogazione" table="Catalogazione" lazy="false"> 
     <id name="id" column="ID">   
     </id>  
     <property name="nome" column="Nome" /> 
     <property name="showBox" column="ShowBox" type="integer"/> 

    </class> 
</hibernate-mapping> 

很簡單。 當我檢索數據庫對象時,showBox屬性始終爲0。 這是檢索的對象列表中

public List<Catalogazione> getAll() throws Exception { 
    List<Catalogazione> catalogazioni = new ArrayList<Catalogazione>(); 
    Session session = null; 
    try { 
     session = SessionFactoryUtil.getInstance().openSession(); 
     String query = "from Catalogazione as cat"; 
     catalogazioni = session.createQuery(query).list(); 
     return catalogazioni; 
    } catch (Exception ex) { 
     // log error 
    } finally { 
     session.close(); 
    } 
} 

這就是它的代碼。 Catalogazioni的每個實例都有showBox = 0,即使在db中有幾個值。 有人可以告訴我爲什麼嗎?此外,ID同樣映射到數據庫上的整數字段,它工作正常...我錯過了什麼?

回答

0

您的二傳手沒有做任何事情:

public void setShowBox(int showBox) { 
} 
^--- 
+0

當然!我知道這是一個愚蠢的問題:(((( 謝謝 – themarcuz