无法实例化默认的tuplizer&在课堂上找不到itemName的getter

时间:2018-01-04 07:17:43

标签: java hibernate

我正在尝试执行该程序,但我收到的错误如下:

Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for itemName in class com.sathya.entity.Item
    ## Unable to instantiate default tuplizer & could not find a getter for itemName in class##


package com.sathya.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;         
import com.sathya.entity.Item;         

public class InsertItem {

    public static void main(String[] args) {
        Configuration config=new Configuration();
        config.configure("com/sathya/config/hibernate.cfg.xml");
        SessionFactory factory=config.buildSessionFactory();
        Session session=factory.openSession();
        Item item=new Item( 1001,"sony",9000);
        Transaction tx=session.beginTransaction();
        session.save(item);
        tx.commit();
        session.close();
        factory.close();
    }
}

我的另一个课是Item:

package com.sathya.entity;

public class Item {
    private int itemId;
    private String itemName;
    private double price;
    public Item()
    {
    }
    public Item(int itemID)
    {
        this.itemId=itemId;
    }
    public Item(int itemID,String itemName,double price)
    {
        this.itemId=itemId;
        this.itemName=itemName;
        this.price=price;
    }
    public int getItemId() {
        return itemId;
    }
    public void setItemId(int itemId) {
        this.itemId = itemId;
    }
    public String getName() {
        return itemName;
    }
    public void setName(String itemName) {
        this.itemName = itemName;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    public String toString()
    {
        return "Item["+itemId+","+itemName+","+price+"]";
    }

}

1 个答案:

答案 0 :(得分:0)

目前你有一个名为getName()的吸气剂 但您的配置需要另一个名称:

  

无法在类com.sathya.entity.Item

中找到itemName的getter

将getter重命名为:getItemName()

这是因为你已经调用了你的变量:

private String itemName;

配置假定您在setter / getter方法中保留该名称。