-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Collection Map of components
PostPosted: Wed Aug 13, 2008 6:23 pm 
Newbie

Joined: Wed Aug 13, 2008 6:08 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.