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!