-->
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: Mapping bidirectional OneToOne with column on non-owner side
PostPosted: Wed Jun 24, 2009 2:03 pm 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Hello,

I have a particular case that I don't know how to handle using annotations. I want to map the join column on the non-owner side.

For example, if I have 2 classes: Body and Head. A body is composed of one Head and a Head belongs to one Body.

As of now, I am able to map this bidirectional OneToOne relationship but by having the foreign key in the Body table. I would like to have the same functionnality as now (the Body is the Owner that manages the relationship) but with the foreign key in the Head.

My current annotations are the following:

Body.class:
Code:
   private Head head;
    @javax.persistence.OneToOne(cascade=CascadeType.ALL)     
    @javax.persistence.JoinColumn(name="HEAD_FK")
    @org.hibernate.annotations.Cascade({CascadeType.DELETE_ORPHAN})
    @org.hibernate.annotations.Fetch(FetchMode.SELECT)
    public Head getHead() {
        return this.head;
    }


Head.class:
Code:
    private Body body;
    @OneToOne(mappedBy="head")     
    public Body getBody() {
        return this.body;
    }


Now I simply want to know how to modify this so that Body is still the Owner but so that the physical column is on the Head table.

Thanks for your help,

Francois


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.