I am trying to use Hibernate to do save/load objects that look like this (these are outlines; I left off the accessors for brevity), but cannot figure out what to place into Item.hbm.xml:
class Item {
String name;
Vec3d position;
}
class Vec3d {
double x;
double y;
double z;
}
Database schema:
create table item (
item_id bigint primary key,
name varchar(64) not null,
x double not null,
y double not null,
z double not null
);
The Item.hbm.xml basically looks like this so far:
...
<class name="Item" table="item">
<id name="id" column="item_id">
<generator class="sequence" />
</id>
<property name="name" type="string" />
<!-- ??? How do I map the position ??? -->
</class>
...
I cannot find documentation on how to get the position vector as a single object, but stored as fields in the same row as the Item class. It seems wasteful to store it in a separate table and incur a join just for reading an Item.
It’s possible that my trouble in finding an answer comes from not knowing the terminology that Hibernate uses for this schema.
This is typically addressed use @Embeddable and @Embedded in hibernate annotations. However, when using a mapping file, you can use the component tag.
http://vuknikolic.wordpress.com/2010/11/27/embeddable-with-hbm-xml/