Hibernate Mapping - 使用property作为键的简单查找表

时间:2013-03-22 04:05:57

标签: hibernate

我对以下课程的hibenate映射感到困惑

public class Order {
    private String orderNumber;
    private List<Component> Components = new ArrayList<Component>();
}

public class Component{
   private String orderNumber;
   private String partNumber;
   private Integer rowNum;
   private Part product;
}

public class Part{
    private String partNumber;
    private String barcodeNumber
    private Barcode barcode;
}
public class Barcode {
    private String barcodeNumber;
    private String itemBarcode;
    private String boxBarcode;
}

HIBERNATE MAPPING

ORDER

<class name="Order" table="Order" node="order" lazy="true">
    <id name="partNumber" unsaved-value="undefined" node="@partNumber">
        <column name="partNumber" not-null="true" />
    </id>
    <bag name="Components" lazy="true" outer-join="false" fetch="select">
        <key column="_PARENT" />
        <one-to-many class="Component" />
    </bag>
</class>

COMPONENT

<class name="Component" table="component" node="order" lazy="true">
    <composite-id unsaved-value="undefined">
        <key-property name="enumber">
            <column name="_PARENT" not-null="true" />
   </key-property>
   <key-property name="rowNum" >
       <column name="_ROWNUM" not-null="true" />
   </key-property>
         <key-property name="rpn" >
             <column name="RPN" not-null="true" />
         </key-property>
    </composite-id>
    <property name="partNumber" node="@partNumber">
        <column name="partNumber" />
    </property>
    <many-to-one lazy="proxy" fetch="join" update="false" insert="false" name="part" class="Part" column="partNumber" node="part" embed-xml="true"></many-to-one>
</class>

PART

<class name="Part" table="Part" node="part" lazy="true">
    <meta attribute="implement-equals">true</meta>
    <cache usage="read-only"/>
    <id name="cpn" type="string" unsaved-value="undefined" node="@cpn">
        <column name="CPN" not-null="true" />
    </id>     
    <property name="barcodeNumber" type="string" node="@barcodeNumber">
        <column name="barcodeNumber" not-null="false" />
    </property>
    <many-to-one  name="Barcode" foreign-key="barcodeNumber" class="Barcode" fetch="select"/>
</class>

BARCODE

<class name="Barcode" table="Barcode" node="barcode" lazy="true">
    <id name="barcodeNumber" unsaved-value="undefined" node="@barcodeNumber">
      <column name="barcodeNumber" not-null="true" />
    </id>
    <property name="itemBarcode" type="string" node="@itemBarcode">
        <column name="itemBarcode" />
    </property>
    <property name="boxBarcode" type="string" node="@boxBarcode">
        <column name="boxBarcode"  />
    </property> 
</class>

我遇到的问题是Part和Barcode类 该零件有一个特殊的barcodeNumber,它将条形码链接到零件 我无法更改数据结构,但想将这些表连接在一起,以便我可以显示包含组件和部件以及条形码的订单列表

映射传递了initail加载但在检索列表时系统失败 org.hibernate.PropertyAccessException:调用Barcode.barcodeNumber的getter时出现IllegalArgumentException

2 个答案:

答案 0 :(得分:0)

barcodeNumber

的getter方法存在问题

itSholudBe

 getBarcodeNumber();

答案 1 :(得分:0)

你必须添加getter和setter.Change你的代码

发件人

    private Barcode barcode;

    private Barcode barcode = new Barcode();