2016-11-25 47 views
0

我得到這個could not resolve property: cart_id of: pojos.Cart異常,當我運行我的項目。我在Netbeans中使用了休眠。我使用Netbeans嚮導刪除並重新添加了幾次Hibernate,但無法工作。我該如何解決這個問題?謝謝。Java Hibernate錯誤:無法解析屬性:cart_id:pojos.Cart

這裏是我的映射文件,

Cart.hbm.xml

<hibernate-mapping> 
<class name="pojos.Cart" table="cart" catalog="design"> 
    <id name="cartId" type="java.lang.Integer"> 
     <column name="cart_id" /> 
     <generator class="identity" /> 
    </id> 
    <property name="date" type="string"> 
     <column name="date" length="10" /> 
    </property> 
    <property name="total" type="java.lang.Double"> 
     <column name="total" precision="22" scale="0" /> 
    </property> 
    <set name="userses" table="users" inverse="true" lazy="true" fetch="select"> 
     <key> 
      <column name="cart_id" not-null="true" /> 
     </key> 
     <one-to-many class="pojos.Users" /> 
    </set> 
    <set name="cartRegisters" table="cart_register" inverse="true" lazy="true" fetch="select"> 
     <key> 
      <column name="cart_id" not-null="true" /> 
     </key> 
     <one-to-many class="pojos.CartRegister" /> 
    </set> 
</class> 
</hibernate-mapping> 

編輯

Cart.java

package pojos; 
// Generated Nov 25, 2016 6:08:52 PM by Hibernate Tools 3.6.0 

import java.util.HashSet; 
import java.util.Set; 

public class Cart implements java.io.Serializable { 

    private Integer cartId; 
    private String date; 
    private Double total; 
    private Set userses = new HashSet(0); 
    private Set cartRegisters = new HashSet(0); 

    public Cart() { 
    } 

    public Cart(String date, Double total, Set userses, Set cartRegisters) { 
     this.date = date; 
     this.total = total; 
     this.userses = userses; 
     this.cartRegisters = cartRegisters; 
    } 

    public Integer getCartId() { 
     return this.cartId; 
    } 

    public void setCartId(Integer cartId) { 
     this.cartId = cartId; 
    } 

    public String getDate() { 
     return this.date; 
    } 

    public void setDate(String date) { 
     this.date = date; 
    } 

    public Double getTotal() { 
     return this.total; 
    } 

    public void setTotal(Double total) { 
     this.total = total; 
    } 

    public Set getUserses() { 
     return this.userses; 
    } 

    public void setUserses(Set userses) { 
     this.userses = userses; 
    } 

    public Set getCartRegisters() { 
     return this.cartRegisters; 
    } 

    public void setCartRegisters(Set cartRegisters) { 
     this.cartRegisters = cartRegisters; 
    } 
} 
+0

你能否提供類pojos.Cart? –

+0

@simas_ch:我發佈pojos:購物車 – Malinda

+0

嗯。可以提供整個項目嗎?也許在github上? –

回答

0

這不是映射。這是cartModal方法getMaxCart()中的查詢:

cr.setProjection(Projections.max("cart_id")); 
+0

是的,但是這段代碼有什麼問題,我在其他文件中使用了這種方法,它在工作嗎? – Malinda

+0

它應該是cartId –

相關問題