Hi,
I'm pretty new at hibernate, so I have been testing it out on a project, everything was going pretty well, till I tried to map the following..
a little model of what I'm trying to map.
Activity has a 1 to 1 relation with ImageCollection, in ImageCollection theres a List holding instances of Image.
The problem now is I want a person to have a picture, the pictures of all persons are saved in 1 "standard" ImageCollection.
So when I map the Person class I somehow have to give the collection_id of the ImageCollection where the picture of the person should be saved in.
I wrote comment in the Person class mapping.
Mapping documents:
Code:
<hibernate-mapping package="com.project.model">
<class name="Activity">
<id name="id" type="long" column="activity_id">
<generator class="native"/>
</id>
<property name="name" not-null="true"/>
<many-to-one name="picturemap" class="ImageCollection" column="collection_id" cascade="all" unique="true"/>
</class>
<class name="ImageCollection">
<id name="id" type="long" column="collection_id">
<generator class="native"/>
</id>
<property name="name" unique="true"/>
<bag name="images" lazy="true" cascade="all">
<key column="collection_id"/>
<one-to-many class="Image"/>
</bag>
</class>
<class name="Image">
<id name="id" type="long" column="picture_id">
<generator class="native"/>
</id>
<property name="path"/>
</class>
<class name="Person">
<id name="id" type="long" column="person_id">
<generator class="native"/>
</id>
<property name="name"/>
<one-to-one name="picture" class="Image" cascade="all"/>
//if I map it like this the collection_id of the picture becomes NULL of course, but I have no idea how it should be done.
</class>
</hibernate-mapping>
Is it possible to map something like this or do I have to start thinking about a whole different approach?
Thx in advance