Hibernate version: 3.2.5 GA / JDK 1.4.2
Mapping documents: see below
Code between sessionFactory.openSession() and session.close(): n/a
Full stack trace of any exception that occurs: none
Name and version of the database you are using: Oracle 10g
The generated SQL (show_sql=true): see below
Debug level Hibernate log excerpt: see below
I am trying to map a Map collection to a component.
class Term {
...
Map events = new HashMap();
public Map getEvents() { return events; }
public void setEvents(Map events) {this.events = events; }
...
}
the objects in the map are of class TermEvent :
class TermEvent {
private Term term;
private TermEventType termEventType;
private Date eventDate;
...
}
The mapping is ( only relevant sections shown )
<hibernate-mapping>
<class name="edu.mit.academic.pe.domain.Term" table="PTV_TERM">
<id name="id" type="java.lang.String">
<column name="TERM_CODE" length="6" not-null="true" />
<generator class="assigned" />
</id>
<map name="events" table="PTR_TERM_EVENT">
<key>
<column name="TERM_CODE" />
</key>
<map-key column="EVENT_TYPE_CODE"
type="edu.mit.academic.pe.persistence.hibernate.TermEventTypeCustomType" />
<composite-element
class="edu.mit.academic.pe.domain.TermEvent">
<parent name="term" />
<property name="eventDate" type="java.util.Date"
length="7" column="TERM_EVENT_DATE" />
</composite-element>
</map>
If I create a Term object with TermEvent objects in the events Map, and save it, the PTR_TERM_EVENT table is correctly modified. However, if I fetch a Term object the contained Map does not have TermEvent objects as values, it has Date objects as values. When the Date objects are null, it does not get an entry in the map.
I thought that this mapping would cause hibernate to materialize a TermEvent object for the composite element, and it would use the map-key, key, and any properties defined to set its attributes.
When the mapping is done on startup, this is what happens :
DEBUG 2008-08-13 17:52:02,026 [main] CollectionSecondPass - Second pass for collection: edu.mit.academic.pe.domain.Term.
events
DEBUG 2008-08-13 17:52:02,026 [main] HbmBinder - Mapped property: eventDate -> TERM_EVENT_DATE
DEBUG 2008-08-13 17:52:02,026 [main] CollectionSecondPass - Mapped collection key: TERM_CODE, index: EVENT_TYPE_CODE, el
ement: TERM_EVENT_DATE
I really do not want element to be TERM_EVENT_DATE ... I need it to be a composite properties of TermEvent. I cannot figure out from the documentation / books how to do that .
Thanks.
|