你要把你的hbm.xml文件和pojo类给贴出来看看,是否配置正确。

解决方案 »

  1.   

    you should create an intermedial table if you want to apply n:m relationshipLike Customer_Order
      

  2.   

    please refer to Hibernate reference document Section 1.3.5 ( Bi-directional association ) for many-to-many configuration.
      

  3.   

    产品表product为多,产品类别表productclass为一,下面是表结构:
    CREATE TABLE [dbo].[SSH_PRODUCTCLASS](
    [ID]numeric(19,0) NOT NULL,
    [NAME][nvarchar] (100) NOT NULL ,
    )
    CREATE TABLE [dbo].[SSH_PRODUCT](
    [ID]numeric(19,0) NOT NULL,
    [NAME][nvarchar] (100) NOT NULL ,
    [PRODUCTCLASSID][smallint] NOT NULL DEFAULT 0,
    )
    Productclass.hbm.xml配置如下:
    <hibernate-mapping>
     
    <class name="com.jacky.reallb.modal.Productclass" table="SSH_PRODUCTCLASS" lazy="false" dynamic-update="true">    <id column="ID" length="13" name="id" type="java.lang.Long" unsaved-value="null">
    <generator class="increment"/>
    </id>    <property name="name" type="java.lang.String" column="NAME" length="100" />
    <set name="product" table="SSH_PRODUCT" cascade="none" lazy="true" inverse="true" order-by="updt desc">
          <key column="PRODUCTCLASSID"/>
          <one-to-many class="com.jacky.reallb.modal.Product"/>
        </set>
        
      </class>
    </hibernate-mapping>
    Product.hbm.xml配置如下:<hibernate-mapping>
     
    <class name="com.jacky.reallb.modal.Product" table="SSH_PRODUCT" lazy="false" dynamic-update="true">    <id column="ID" length="13" name="id" type="java.lang.Long" unsaved-value="null">
    <generator class="increment"/>
    </id>    <property name="name" type="java.lang.String" column="NAME" length="100" />    <many-to-one
            name="productclass"                               
            class="com.jacky.reallb.modal.Productclass"                                  
            column="PRODUCTCLASSID"   
    cascade="none" 
    not-null="true" 
    /> 
     
      </class>
    </hibernate-mapping>
    我以前用过的一段代码,你参考一下把。