I have a situation that is a little unique to an application that is being developed and curious if Hibernate is able to handle it. So far I have been messing around with it but haven't got it to work. I will be using example classes / data tables but it reflects a similar situation to the application. The mapping is:
Code:
<class name="Person">
<id name="id">
<generator class="assigned"/>
</id>
<set name="events" table="PERSON_EVENT">
<key column="PERSON_ID"/>
<many-to-many column="EVENT_ID" class="Event"/>
</set>
</class>
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="assigned"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
What I am needing is the ability for the Person class objects to not be persisted but when I instantiate a person it will load the corresponding events for that person from the database and populate the set. As well if the events for the person change within the set then an update on the person object would persist those associations but would not try to persist the person itself.
Reasoning behind this is that the person data is being maintained in a separate application so we don't want to duplicate the properties of the person class. Within the other application there is the details about the person (i.e. name, address, etc) and within this application there is just information about the event with the person_event and event tables. I would like to still work with the base classes of Person and Event without having to create some custom PersonEvent object that would need to expose the ability to allow a retrieval of a list of events for a person.
Any way for hibernate to provide this functionality?
Thanks
--
Shawn Clark