These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Specifying sequence in <join mapping - Oracle
PostPosted: Wed Jul 12, 2006 9:53 am 
Newbie

Joined: Mon Feb 20, 2006 1:40 am
Posts: 7
Location: Hyderabad
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.