获取为以下类生成空ID:com.cpos.pojo.Items类

时间:2019-01-04 14:39:16

标签: java hibernate

我有三个POJO

  • 收据
  • Rctransaction
  • 物品

我先将数据插入Receivings,然后再插入RctransactionItems
但是我遇到Items类的异常
我没有使用@annotations

POJO从id生成Rctransaction,它是自动递增的,不是合成的一部分。

但是不会从Items创建,它是自动递增的,不属于合成。
我在想这是否是异常原因。

所以我得到:

  

org.hibernate.id.IdentifierGenerationException:生成的null ID   for:class com.cpos.pojo.Items

两个类ReceivingsItems都具有组成
ReceivingsIdItemsId

类如下:
Receivings.java

public class Receivings implements java.io.Serializable {

    private ReceivingsId id;
    private Suppliers suppliers;
    private String itemName;
    private String category;
    private double wholesalePrice;
    private double retailPrice;
    private long tax1;
    private long tax2;
    private String type1;
    private String type2;
    private int quantityStock;
    private int receivingQuantity;
    private int recorderLevel;
    private String receivingDate;
    private double discount;
    private Set itemses = new HashSet(0);
    private Set rctransactions = new HashSet(0);

    public Receivings() {
        this.id = new ReceivingsId();
    }

    public Receivings(ReceivingsId id, Suppliers suppliers, String itemName, String category, double wholesalePrice, double retailPrice, long tax1, long tax2, String type1, String type2, int quantityStock, int receivingQuantity, int recorderLevel, String receivingDate, double discount) {
        this.id = id;
        this.suppliers = suppliers;
        this.itemName = itemName;
        this.category = category;
        this.wholesalePrice = wholesalePrice;
        this.retailPrice = retailPrice;
        this.tax1 = tax1;
        this.tax2 = tax2;
        this.type1 = type1;
        this.type2 = type2;
        this.quantityStock = quantityStock;
        this.receivingQuantity = receivingQuantity;
        this.recorderLevel = recorderLevel;
        this.receivingDate = receivingDate;
        this.discount = discount;
    }

    public Receivings(ReceivingsId id, Suppliers suppliers, String itemName, String category, double wholesalePrice, double retailPrice, long tax1, long tax2, String type1, String type2, int quantityStock, int receivingQuantity, int recorderLevel, String receivingDate, double discount, Set itemses, Set rctransactions) {
        this.id = id;
        this.suppliers = suppliers;
        this.itemName = itemName;
        this.category = category;
        this.wholesalePrice = wholesalePrice;
        this.retailPrice = retailPrice;
        this.tax1 = tax1;
        this.tax2 = tax2;
        this.type1 = type1;
        this.type2 = type2;
        this.quantityStock = quantityStock;
        this.receivingQuantity = receivingQuantity;
        this.recorderLevel = recorderLevel;
        this.receivingDate = receivingDate;
        this.discount = discount;
        this.itemses = itemses;
        this.rctransactions = rctransactions;
    }

    public ReceivingsId getId() {
        return this.id;
    }

    public void setId(ReceivingsId id) {
        this.id = id;
    }

    public Suppliers getSuppliers() {
        return this.suppliers;
    }

    public void setSuppliers(Suppliers suppliers) {
        this.suppliers = suppliers;
    }

    public String getItemName() {
        return this.itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getCategory() {
        return this.category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public double getWholesalePrice() {
        return this.wholesalePrice;
    }

    public void setWholesalePrice(double wholesalePrice) {
        this.wholesalePrice = wholesalePrice;
    }

    public double getRetailPrice() {
        return this.retailPrice;
    }

    public void setRetailPrice(double retailPrice) {
        this.retailPrice = retailPrice;
    }

    public long getTax1() {
        return this.tax1;
    }

    public void setTax1(long tax1) {
        this.tax1 = tax1;
    }

    public long getTax2() {
        return this.tax2;
    }

    public void setTax2(long tax2) {
        this.tax2 = tax2;
    }

    public String getType1() {
        return this.type1;
    }

    public void setType1(String type1) {
        this.type1 = type1;
    }

    public String getType2() {
        return this.type2;
    }

    public void setType2(String type2) {
        this.type2 = type2;
    }

    public int getQuantityStock() {
        return this.quantityStock;
    }

    public void setQuantityStock(int quantityStock) {
        this.quantityStock = quantityStock;
    }

    public int getReceivingQuantity() {
        return this.receivingQuantity;
    }

    public void setReceivingQuantity(int receivingQuantity) {
        this.receivingQuantity = receivingQuantity;
    }

    public int getRecorderLevel() {
        return this.recorderLevel;
    }

    public void setRecorderLevel(int recorderLevel) {
        this.recorderLevel = recorderLevel;
    }

    public String getReceivingDate() {
        return this.receivingDate;
    }

    public void setReceivingDate(String receivingDate) {
        this.receivingDate = receivingDate;
    }

    public double getDiscount() {
        return this.discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

    public Set getItemses() {
        return this.itemses;
    }

    public void setItemses(Set itemses) {
        this.itemses = itemses;
    }

    public Set getRctransactions() {
        return this.rctransactions;
    }

    public void setRctransactions(Set rctransactions) {
        this.rctransactions = rctransactions;
    }

}

ReceivingsId.java

public class ReceivingsId  implements java.io.Serializable {


     private int id;
     private int barcode;

    public ReceivingsId() {
    }

    public ReceivingsId(int id, int barcode) {
       this.id = id;
       this.barcode = barcode;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public int getBarcode() {
        return this.barcode;
    }

    public void setBarcode(int barcode) {
        this.barcode = barcode;
    }


   public boolean equals(Object other) {
         if ( (this == other ) ) return true;
         if ( (other == null ) ) return false;
         if ( !(other instanceof ReceivingsId) ) return false;
         ReceivingsId castOther = ( ReceivingsId ) other; 

         return (this.getId()==castOther.getId())
 && (this.getBarcode()==castOther.getBarcode());
   }

   public int hashCode() {
         int result = 17;

         result = 37 * result + this.getId();
         result = 37 * result + this.getBarcode();
         return result;
   }   


}

Items.java

    public class Items implements java.io.Serializable {

    private ItemsId id;
    private Receivings receivings;
    private String itemName;
    private String category;
    private int supid;
    private double wholesalePrice;
    private double retailPrice;
    private long tax1;
    private long tax2;
    private String type1;
    private String type2;
    private int quantityStock;
    private int quantity;
    private int recorderLevel;
    private String itemAddedDate;
    private double discount;

    public Items() {
        this.receivings = new Receivings();
    }

    public Items(ItemsId id, Receivings receivings, String itemName, String category, int supid, double wholesalePrice, double retailPrice, long tax1, long tax2, String type1, String type2, int quantityStock, int quantity, int recorderLevel, String itemAddedDate, double discount) {
        this.id = id;
        this.receivings = receivings;
        this.itemName = itemName;
        this.category = category;
        this.supid = supid;
        this.wholesalePrice = wholesalePrice;
        this.retailPrice = retailPrice;
        this.tax1 = tax1;
        this.tax2 = tax2;
        this.type1 = type1;
        this.type2 = type2;
        this.quantityStock = quantityStock;
        this.quantity = quantity;
        this.recorderLevel = recorderLevel;
        this.itemAddedDate = itemAddedDate;
        this.discount = discount;
    }

    public ItemsId getId() {
        return this.id;
    }

    public void setId(ItemsId id) {
        this.id = id;
    }

    public Receivings getReceivings() {
        return this.receivings;
    }

    public void setReceivings(Receivings receivings) {
        this.receivings = receivings;
    }

    public String getItemName() {
        return this.itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getCategory() {
        return this.category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public int getSupid() {
        return this.supid;
    }

    public void setSupid(int supid) {
        this.supid = supid;
    }

    public double getWholesalePrice() {
        return this.wholesalePrice;
    }

    public void setWholesalePrice(double wholesalePrice) {
        this.wholesalePrice = wholesalePrice;
    }

    public double getRetailPrice() {
        return this.retailPrice;
    }

    public void setRetailPrice(double retailPrice) {
        this.retailPrice = retailPrice;
    }

    public long getTax1() {
        return this.tax1;
    }

    public void setTax1(long tax1) {
        this.tax1 = tax1;
    }

    public long getTax2() {
        return this.tax2;
    }

    public void setTax2(long tax2) {
        this.tax2 = tax2;
    }

    public String getType1() {
        return this.type1;
    }

    public void setType1(String type1) {
        this.type1 = type1;
    }

    public String getType2() {
        return this.type2;
    }

    public void setType2(String type2) {
        this.type2 = type2;
    }

    public int getQuantityStock() {
        return this.quantityStock;
    }

    public void setQuantityStock(int quantityStock) {
        this.quantityStock = quantityStock;
    }

    public int getQuantity() {
        return this.quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public int getRecorderLevel() {
        return this.recorderLevel;
    }

    public void setRecorderLevel(int recorderLevel) {
        this.recorderLevel = recorderLevel;
    }

    public String getItemAddedDate() {
        return this.itemAddedDate;
    }

    public void setItemAddedDate(String itemAddedDate) {
        this.itemAddedDate = itemAddedDate;
    }

    public double getDiscount() {
        return this.discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

}

ItemsId.java

public class ItemsId  implements java.io.Serializable {


     private int id;
     private int barcode;

    public ItemsId() {
    }

    public ItemsId(int id, int barcode) {
       this.id = id;
       this.barcode = barcode;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public int getBarcode() {
        return this.barcode;
    }

    public void setBarcode(int barcode) {
        this.barcode = barcode;
    }


   public boolean equals(Object other) {
         if ( (this == other ) ) return true;
         if ( (other == null ) ) return false;
         if ( !(other instanceof ItemsId) ) return false;
         ItemsId castOther = ( ItemsId ) other; 

         return (this.getId()==castOther.getId())
 && (this.getBarcode()==castOther.getBarcode());
   }

   public int hashCode() {
         int result = 17;

         result = 37 * result + this.getId();
         result = 37 * result + this.getBarcode();
         return result;
   }   


}  

Receivings.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 4 Jan, 2019 7:29:40 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
    <class name="com.cpos.pojo.Receivings" table="receivings" catalog="CPOS" optimistic-lock="version">
        <composite-id name="id" class="com.cpos.pojo.ReceivingsId">
            <key-property name="id" type="int">
                <column name="id" />
            </key-property>
            <key-property name="barcode" type="int">
                <column name="barcode" />
            </key-property>
        </composite-id>
        <many-to-one name="suppliers" class="com.cpos.pojo.Suppliers" fetch="select">
            <column name="supid" not-null="true" />
        </many-to-one>
        <property name="itemName" type="string">
            <column name="`item name`" not-null="true" />
        </property>
        <property name="category" type="string">
            <column name="category" not-null="true" />
        </property>
        <property name="wholesalePrice" type="double">
            <column name="`wholesale price`" precision="22" scale="0" not-null="true" />
        </property>
        <property name="retailPrice" type="double">
            <column name="`retail price`" precision="22" scale="0" not-null="true" />
        </property>
        <property name="tax1" type="long">
            <column name="tax1" precision="10" scale="0" not-null="true" />
        </property>
        <property name="tax2" type="long">
            <column name="tax2" precision="10" scale="0" not-null="true" />
        </property>
        <property name="type1" type="string">
            <column name="type1" not-null="true" />
        </property>
        <property name="type2" type="string">
            <column name="type2" not-null="true" />
        </property>
        <property name="quantityStock" type="int">
            <column name="`quantity stock`" not-null="true" />
        </property>
        <property name="receivingQuantity" type="int">
            <column name="`receiving quantity`" not-null="true" />
        </property>
        <property name="recorderLevel" type="int">
            <column name="`recorder level`" not-null="true" />
        </property>
        <property name="receivingDate" type="string">
            <column name="`receiving date`" not-null="true" />
        </property>
        <property name="discount" type="double">
            <column name="discount" precision="10" scale="0" not-null="true" />
        </property>
        <set name="itemses" table="items" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="rcid" not-null="true" />
                <column name="barcode" not-null="true" />
            </key>
            <one-to-many class="com.cpos.pojo.Items" />
        </set>
        <set name="rctransactions" table="rctransaction" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="rcid" not-null="true" />
                <column name="barcode" not-null="true" unique="true" />
            </key>
            <one-to-many class="com.cpos.pojo.Rctransaction" />
        </set>
    </class>
</hibernate-mapping>

Items.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 4 Jan, 2019 7:29:40 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
    <class name="com.cpos.pojo.Items" table="items" catalog="CPOS" optimistic-lock="version">
        <composite-id name="id" class="com.cpos.pojo.ItemsId">
            <key-property name="id" type="int">
                <column name="id" />
            </key-property>
            <key-property name="barcode" type="int">
                <column name="barcode" />
            </key-property>
        </composite-id>
        <many-to-one name="receivings" class="com.cpos.pojo.Receivings" update="false" insert="false" fetch="select">
            <column name="rcid" not-null="true" />
            <column name="barcode" not-null="true" />
        </many-to-one>
        <property name="itemName" type="string">
            <column name="`item name`" not-null="true" />
        </property>
        <property name="category" type="string">
            <column name="category" not-null="true" />
        </property>
        <property name="supid" type="int">
            <column name="supid" not-null="true" />
        </property>
        <property name="wholesalePrice" type="double">
            <column name="`wholesale price`" precision="22" scale="0" not-null="true" />
        </property>
        <property name="retailPrice" type="double">
            <column name="`retail price`" precision="22" scale="0" not-null="true" />
        </property>
        <property name="tax1" type="long">
            <column name="tax1" precision="10" scale="0" not-null="true" />
        </property>
        <property name="tax2" type="long">
            <column name="tax2" precision="10" scale="0" not-null="true" />
        </property>
        <property name="type1" type="string">
            <column name="type1" not-null="true" />
        </property>
        <property name="type2" type="string">
            <column name="type2" not-null="true" />
        </property>
        <property name="quantityStock" type="int">
            <column name="`quantity stock`" not-null="true" />
        </property>
        <property name="quantity" type="int">
            <column name="quantity" not-null="true" />
        </property>
        <property name="recorderLevel" type="int">
            <column name="`recorder level`" not-null="true" />
        </property>
        <property name="itemAddedDate" type="string">
            <column name="`item added date`" not-null="true" />
        </property>
        <property name="discount" type="double">
            <column name="discount" precision="10" scale="0" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

0 个答案:

没有答案
相关问题