0

我被以下类的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;
}

休眠映射

命令

<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>

零件

<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>

部分

<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>

条码

<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 类 Part 有一个特殊的barcodeNumber 将 Barcode 链接到 Part 我无法更改数据结构,但想将这些表连接在一起以便我可以显示订单列表有组件和零件和条形码

映射通过初始加载,但在检索列表时系统失败 org.hibernate.PropertyAccessException: IllegalArgumentException 发生调用 Barcode.barcodeNumber 的 getter

4

2 回答 2

0

这是getter方法的问题barcodeNumber

它应该是

 getBarcodeNumber();
于 2013-03-22T04:21:48.317 回答
0

您必须添加 getter 和 setter。更改您的代码

    private Barcode barcode;

    private Barcode barcode = new Barcode();
于 2013-03-22T06:12:28.290 回答