-->
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: Subclasses with differently named id columns
PostPosted: Fri Mar 18, 2005 3:48 pm 
Newbie

Joined: Fri Mar 18, 2005 3:23 pm
Posts: 7
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

I have an object heirarchy with a table per object where each subclass has a different name for the key.

Object (id column is org_id)
Organization (id column is org_id)
GovernmentOrg (id column is gov_id)
MilitaryOrg (id column is mil_org_id)

I would like to map this using join-subclass syntax, but am not sure if there is a way to specify that the id column is named differently for the subclasses. So for the military org, its id would be in the parent tables, just in differently named columns. Thanks in advance.

Hibernate version: 3.0rc1

Mapping documents:


Code:
<class name="Object" table="objects">
    <id name="objId" column="obj_id"/>
    <join-subclass name="Organization" table="organizations">
       <!--what should this be to map to org_id ??? -->
       <key column="obj_id"/>
        <property name="orgName" column="org_name"/>
        ...
       
        <join-subclass name="GovOrg" table="government_orgs">
            <!--what should this be to map to gov_id ???-->
            <key column="obj_id"/>
            <property name="governmentBranch" column="gov_branch"/>
            ...
           
            <join-subclass name="MilitaryOrg" table="military_orgs">
                <!--what should this be to map to mil_id ???-->
                <key column="obj_id"/>

            </join-subclass>
           
        </join-subclass>       
    </join-subclass>   
<class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 12:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<key column="gov_id"/>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 1:13 pm 
Beginner
Beginner

Joined: Mon Mar 28, 2005 12:58 pm
Posts: 27
I'm also trying to do inheritance using hibernate 3.0 rc1:

Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Person
{
    private String id;

    @Id
    @Column(name="person_id")
    public String getId()
    {
        return id;
    }
    ...
}


@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@InheritanceJoinColumn(name = "person_id")
public class CrazyPerson extends Person
{
    private String crazyId;

    public String getCrazyId()
    {
        return crazyId;
    }
}



I want to make the crazyId to be the same as the id in the parent class but I don't know how to do that using annotations. Essentially the originating post shows how to do it using XML but I haven't seen anything using annotations. Is this possible just using EJB3 annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 29, 2005 5:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Best solution
getCrazyId() { super.getId() }

Otherwise

@Column(name="person_id", insertable = false, upatable = "false")
getCrazyId()

_________________
Emmanuel


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.