This is about specifying a sequence in <join mapping.
Database : ORACLE.
Tables :
CREATE TABLE TASK ( TASK_CODE NUMBER(10,0) NOT NULL ENABLE, TASK_ID VARCHAR2(250 BYTE) DEFAULT '' NOT NULL ENABLE, TASK_NAME VARCHAR2(250 BYTE) DEFAULT '' NOT NULL ENABLE, CONSTRAINT PK__TASK__58D1301D PRIMARY KEY (TASK_CODE) ENABLE );
CREATE TABLE TASK_TIMELINE ( TASK_TIMELINE_CODE NUMBER(10,0) NOT NULL ENABLE, TASK_CODE NUMBER(10,0) DEFAULT NULL, SCHEDULED_START DATE DEFAULT NULL, SCHEDULED_END DATE DEFAULT NULL, CONSTRAINT PK__TASK_TIMELINE__011F1899 PRIMARY KEY (TASK_TIMELINE_CODE) ENABLE, CONSTRAINT FK__TASK_TIME__TASK___0D84EF7E FOREIGN KEY (TASK_CODE) REFERENCES TASK (TASK_CODE) ON DELETE CASCADE ENABLE );
Primary Key description :
TASK_CODE (PRIMARY KEY, SEQUENCE IN ORACLE, AUTOINCR. IN MYSQL, IDENTITY IN MSSQL)
TASK_TIMELINE_CODE (PRIMARY KEY, SEQUENCE IN ORACLE, AUTOINCR. IN MYSQL, IDENTITY IN MSSQL)
<class name="ProjectData" table="task">
<id name="primaryKey" column="TASK_CODE">
<generator class="native">
<param name="sequence">S_TASK</param>
</generator>
</id>
<property name="ID" column="TASK_ID" update="false"/>
<property name="name" column="TASK_NAME"/>
<join table="task_timeline" fetch="join">
<key column="TASK_CODE"/>
<property name="startDate" column="SCHEDULED_START"/>
<property name="endDate" column="SCHEDULED_END"/>
</join>
</class>
I am trying to insert a record in table 'task' and 'task_timeline' using mapped class 'ProjectData'.
I have sequences for tables 'task' and 'task_timeline' to generate primary keys. I specify the sequence for 'task' as following :
<generator class="native"> <param name="sequence">S_TASK</param> </generator>
When a record is inserted into task it must also insert a record into task_timeline using the join.
How do I specify the sequence name for the join table task_timeline.
I tried with many-to-one but it fails to insert the primary key of task into task_timeline because task_codeof task is mapped twice, once as <id> and once as <many-to-one> with insert="false" update="false" to avoid repeated mapping on that column.
What are the alternatives for achieving these type of inserts using <join> where joined table also has its own primary key and a sequence.
This works perfectly with MySQL and MSSQL servers and in our context join is required and <set>, <bag> or other such collections.
|