-->
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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Joined subclass and primary foreign keys
PostPosted: Wed Feb 11, 2004 6:20 am 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
Hi ppl,


I understand that, in a <joind-subclass>, the <key> property identifies the joined column, but what about primary foreign keys? Can i use <id> or <composite-id> right after the <key> tag?

Cya!
Thiago Souza


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 8:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The id is stored in the parent class and thus in the parent table.
It's inconsistent to store an id in <subclasses> or <joined-subclasses>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 8:50 am 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
Ok, but i'm talking about FOREIGN keys... i know that the primary key is generated in parent tables, but I wanna know about foreign keys that should be primary keys... got it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 9:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
<key> and key colum(s) is a pure technical stuff.

If you want this column to be involved in a many-to-one, then add insert="false" update="false".

I don't understand "foreign keys that should be primary keys".

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 10:09 am 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
It's primary foreign key! They are foreign keys that are grouped in primary keys! As in identifying relashionship in relational database...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 10:16 am 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
My problem is that I have an identifying relationship in a subclass... so, as it is a subclass, it has and id (used to make the joins in the superclasses), but i have primary foreing keys that comes from the identifying relationship, if it were UNidentifying, ok, I would have a normal collection, but it isn't, the foreign key should be primary foreign key...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
All right I give up. Maybe a native english user will understand.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 4:31 pm 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
Watch this...

-----------
| Table A | (Superclass)
-----------
|PK (id) |
----------
|
| <partitioning>
|
-----------
| Table B | (Subclass)
-----------
|PK (id) |
|PF (id_c)|
----------
|
| <Identifying relationship>
|
-----------
| Table C |
-----------
|PK (id) |
----------


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 4:32 pm 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
So... how I would map Table B if it has the joiner key column AND a primary foreign key...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 5:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I don't know what you mean with "partitioning" and "identifying relationship", but as far as I understand you you could simply map this with a relationship tag (one-to-one or many-to-one or such) inside the joined-subclass mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 6:03 pm 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
Ok, I understand this... but, shouldn't I need to map somewhere that the column in the <many-to-one> is a primary key in the database?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 6:26 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
No.

(I'm a native english speaker and I'm having a hard time too. :P )


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 6:31 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Code:
<hibernate-mapping>

    <class name="DataObject" table="data_objects">

        <id name="id" type="long">
            <generator class="native"/>
        </id>
       
        <joined-subclass name="Movie" table="movies">
                   
            <key column="id"/>
           
            <many-to-one name="trailer" class="MovieTrailer"/>
       
        </joined-subclass>
       
        <joined-subclass name="MovieTrailer" table="trailers">
               
            <key column="id"/>
           
        </joined-subclass>
       
    </class>
   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 6:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah, Greg, the master of examples :) Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 6:40 pm 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
Ok! Thanks! But those terms "partitioning" and "identifying relationships" I learned in university and I have seeing it in a lot of database design tools... you ppl should know them =)

But thanks for tha help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next

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.