Reputation: 187
i search the web for answer, but all the answers refer to composite id PK. i want two map two columns of type long to PK. one should be regular generated id, and the other should be regular long field.
i have the following mapping:
<class name="com.company.MyTable" table="My_Table">
<id name="id" column="id">
<generator class="assigned"/>
</id>
<property name="jobId" column="job_id" type="long" index="oes_job_id_idx" />
<property name="serverId" column="server_id" type="long"/>
</class>
i want to add to the PK the job_id column. how do i do that?
Upvotes: 0
Views: 194
Reputation: 18639
Please look at this questions there is a full solution for composite Primary keys:
And then
Mapping same class relation - continuation
Hope it helps.
Upvotes: 0
Reputation: 597114
Primary keys, by definition should be the unique key with the fewest columns possible:
It doesn't really give you a benefit to create a separate index either - so stick to the generated field as primary key. So, hibernate doesn't support that because it is a wrong thing to do.
Upvotes: 2