views:

13

answers:

1

I have a table for class UserStatus ( userId varchar, statusId bigint). Set statusId to autoincrement and specify userId as primary key for some optimisation because most request goes with userId. Using Eclipse. After reverse engineering receive such file:

<class name="xxx.UserStatus" table="user_statuses"
    catalog="xxx">
    <id name="userId" type="java.lang.Long">
        <column name="UserId" />
        <generator class="identity" />
    </id>
    <property name="statusId" type="long">
        <column name="StatusId" not-null="true" unique="true" />
    </property>
    <property name="status" type="string">
        <column name="Status" length="256" not-null="true" />
    </property>
    <property name="updateTime" type="timestamp">
        <column name="UpdateTime" length="19" not-null="true" />
    </property>
</class>

but it's not what i want cos statusId is must database generated. StatusId must be autogenerated.

Any solution?

A: 

There are built in Generator in Hibernate. "identity" should take care of autoincrement in some of the databases like mysql, db2 etc. You can use "sequence" in case of oracle. FYR http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-id

Ck-

related questions