请教下<hibernate-mapping>
    <class name="com.song.shopping.entity.User" table="SHOPPING_SONG_USER" schema="OPENLAB">
        <id name="userId" type="long">
            <column name="USER_ID" precision="22" scale="0" />
            <generator class="hilo" />
        </id>
        <property name="username" type="string">
            <column name="USERNAME" length="32" not-null="true" unique="true" />
        </property>
        <property name="userpwd" type="string">
            <column name="USERPWD" length="32" not-null="true" />
        </property>
        <property name="useremail" type="string">
            <column name="USEREMAIL" length="64" not-null="true" />
        </property>
        <property name="telphone" type="string">
            <column name="TELPHONE" length="20" />
        </property>
        <set name="shoppingSongOrders" inverse="true">
            <key>
                <column name="USER_ID" precision="22" scale="0" not-null="true" />
            </key>
            <one-to-many class="com.song.shopping.entity.Order" />
        </set>
    </class>
</hibernate-mapping>
<id name="userId" type="long">
            <column name="USER_ID" precision="22" scale="0" />
            <generator class="hilo" />
        </id>
上面的配置文件中 主键必须有序列吗?有没有没有序列的时候,没有序列的情况下如何写配置文件?

解决方案 »

  1.   

    <generator class="hilo" />这个意味着 你的主建是由 hilo这个类创建的,所以在装载数据的时候调用这个类来产生主建。不过估计楼主的本意不是这样的。
    如果想自增 ,oracle里面有sequence来实现<generator class="sequence">
         <param name="sequence">自己创建的sequence</param>
    </generator>
    这样就不需要你去关心主建,程序会自己从sequence里面去取得
      

  2.   

    id name="userId" type="long">
      <column name="USER_ID" precision="22" scale="0" />
      <generator class="native" />
      </id>
      

  3.   


    native 就是不使用序列?是这个意思吧?
      

  4.   

    native 策略是从identity,sequence,hilo中自动选择,这取决于数据库的支持。
    hibernate的ID是必须的,identity可以配置标识字段...具体的要自己去找了
      

  5.   

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="com.ruining.pojo">
    <class
    name="DictItem"
    table="DICT_ITEM"
    >
    <id name="dictid" type="string" column="DICTID">
    <generator class="sequence">
    <param name="sequence">SEQ_DICTITEM</param>
    </generator>
    </id>

    <property
    name="groupid"
    column="GROUPID"
    type="string"
    not-null="false"
    length="64"
    />
    <property
    name="dictname"
    column="DICTNAME"
    type="string"
    not-null="false"
    length="64"
    />
    <property
    name="shortname"
    column="SHORTNAME"
    type="string"
    not-null="false"
    length="3"
    />
    <property
    name="updatetime"
    column="UPDATETIME"
    type="date"
    not-null="false"
    length="7"
    />
    </class>
    </hibernate-mapping>
      

  6.   

    <generator class="assigned"> 程序中自己指定主键
      

  7.   

    主键必须要有序列一般的序列形式是由数字组成的,这个就可以用sequence实现,很方便
    但特殊情况下,主键可能由数字+字母,如:5555xxyx,我曾经想实现这种情况的,但没实现....
      

  8.   

    <id name="userId" type="long">
      <column name="USER_ID" precision="22" scale="0" />
      <generator class="identity" />
      </id>
    用identity