-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping Keys with Different Names
PostPosted: Mon Feb 07, 2005 6:21 pm 
Newbie

Joined: Mon Feb 07, 2005 6:07 pm
Posts: 3
I am trying to map two tables that have different names for the primary/foreign keys. Is this possible?

Code:
Table1
   AGENT_ID (PK)
   COMPANY_CODE (PK)

Table2
   AGENT_ID (FK)
   COMPANY_CD (FK)


Code:
select t1.agent_id, t2.agent_id from table1 t1, table2 t2 where t1.agent_id = t2.agent_id and t1.company_code = t2.company_cd

The column types and lengths are the same. Unfortunately, I don't have the option to rename the columns.

Thanks,
Sean


Top
 Profile  
 
 Post subject: SQL
PostPosted: Mon Feb 07, 2005 6:28 pm 
Newbie

Joined: Tue Dec 14, 2004 2:57 pm
Posts: 12
This is more of an SQL question; the answer is yes.

Using a CREATE TABLE statement
The syntax for creating a foreign key using a CREATE TABLE statement is:
Code:
    CREATE TABLE table_name
    (column1 datatype null/not null,
    column2 datatype null/not null,
    ...
    CONSTRAINT fk_column
      FOREIGN KEY (column1, column2, ... column_n)
      REFERENCES parent_table (column1, column2, ... column_n)
    );



Top
 Profile  
 
 Post subject: Mapping Keys with Different Names
PostPosted: Mon Feb 07, 2005 6:39 pm 
Newbie

Joined: Mon Feb 07, 2005 6:07 pm
Posts: 3
Code:
<class name="MasterProducer" table="MPR">
      <composite-id>
         <key-property name="MasterAgentId" column="MSTR_AGENT_ID" type="string" length="10" />
         <key-property name="MasterCompanyCode" column="MSTR_COMPANY_CODE" type="string" length="3" />
      </composite-id>
.....columns.....

      <set name="Licenses" cascade="all" inverse="true" lazy="true">
         <key>
            <column name="[b]COMPANY_CODE[/b]" length="3" />
            <column name="AGENT_ID" length="10" />
         </key>
         <one-to-many class="License" />
      </set>

</class>

<class name="License" table="LICENSE">
      <composite-id>
         <key-property name="CompanyCode" column="COMPANY_CODE" type="string" length="3" />
         <key-property name="AgentId" column="AGENT_ID" type="string" length="10" />   
      </composite-id>
.....columns.....
</class>


This is actually what I am dealing with. I don't know how to say MasterProducer.COMPANY_CODE = License.COMPANY_CD.


Top
 Profile  
 
 Post subject: Mapping Keys with Different Names
PostPosted: Mon Feb 07, 2005 6:41 pm 
Newbie

Joined: Mon Feb 07, 2005 6:07 pm
Posts: 3
There was a typo in the last sentence of the last reply.
Quote:
I don't know how to say MasterProducer.COMPANY_CODE = License.COMPANY_CD.

Should read:
Quote:
I don't know how to say MasterProducer.MSTR_COMPANY_CODE = License.COMPANY_CODE.


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

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.