-->
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: One-to-one mapping via FK that is also the PK
PostPosted: Sun Dec 23, 2012 7:44 pm 
Newbie

Joined: Thu Sep 13, 2012 7:35 pm
Posts: 3
Hello all!
I have trouble coming up with a proper XML mapping for my case and wanted to see if somebody could help me with it. I have 2 tables, a primary table with some fields and an auxiliary table that contains some more fields. They have a one-to-one relationship. The auxiliary table has a PK that is also an FK against the primary table. Here is a mock-up in pseudo-code:

Code:
create table Foo (fooId integer, /*some fields here*/ primary key (fooId));
create table Bar (fooId integer, /*some fields here*/ primary key (fooId), foreign key fooId references Foo(fooId));


What I've been able to piece together from online resources, ended up being something like this:
Code:
<class name="Foo" table="Foo" optimistic-lock="version">
    <id name="fooId" column="fooId" type="long" access="field">
        <generator class="native"/>
    </id>
    <version column="timestamp" name="timestamp" type="timestamp" unsaved-value="null"/>
    <one-to-one name="bar" class="Bar" cascade="none"/>
    <!-- fields -->
</class>

<class name="Bar" table="Bar">
    <id name="fooId" column="fooId" type="long" access="field">
        <generator class="foreign">
            <param name="property">foo</param>
        </generator>
    </id>
    <one-to-one name="foo" class="Foo" cascade="none"/>
    <!-- fields -->
</class>


However, the above does not work and I cannot tell the exact error right now as I have since tried numerous other iterations of doing it, but they all inevitably fail.

The other caveat is also that Bar, the auxiliary table, has to be read-only from the Java side. I haven't really found a way of doing that yet either.

I am looking for any input on the correct way of mapping the FK+PK relationship, and also on how to make the dependent table and class read-only if possible.

Thank you ahead of time for taking a look!


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.