-->
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.  [ 3 posts ] 
Author Message
 Post subject: Map many-to-many index problem
PostPosted: Thu Mar 02, 2006 5:55 am 
Newbie

Joined: Thu Mar 02, 2006 4:26 am
Posts: 2
Hibernate version: 3.1


I can't make many-to-many mapping where Map's index located in entity table, not in relation table.

This is sample from Chapter 1.3.2. A unidirectional Set-based association (http://www.hibernate.org/hib_docs/v3/re ... -unidirset)


table EVENTS
*EVENT_ID
EVENT_DATE
TITLE


table PERSON_EVENT
*EVENT_ID
*PERSON_ID


table PERSON
*PERSON_ID
AGE
FIRSTNAME
LASTNAME


Code:
<class name="events.Person" table="PERSON">
    <id name="id" column="PERSON_ID">
        <generator class="native"/>
    </id>
    <property name="age"/>
    <property name="firstname"/>
    <property name="lastname"/>

    <set name="events" table="PERSON_EVENT">
        <key column="PERSON_ID"/>
        <many-to-many column="EVENT_ID" class="events.Event"/>
    </set>

</class>


In my case I can't use Set, I need Map where index (key field for Map) is TITLE field in table EVENTS.

Code:
<class name="events.Person" table="PERSON">
    <id name="id" column="PERSON_ID">
        <generator class="native"/>
    </id>
    <property name="age"/>
    <property name="firstname"/>
    <property name="lastname"/>

    <map name="events" table="PERSON_EVENT">
        <key column="PERSON_ID"/>
        <index column="TITLE" type="com.avetti.simplemerce.HibernateEscapedString"/>
        <many-to-many column="EVENT_ID" class="events.Event"/>
    </map>

</class>



When I use this mapping I have error. In this case Hibernate search field "TITLE" in the table "PERSON_EVENT", not in the table "EVENTS".
Can anybody help me with mapping (without modification of database structure, i can't make "TITLE" as key field in table PERSON_EVENT)?

Sorry, my English isn't good.
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 10:03 am 
Newbie

Joined: Thu Mar 02, 2006 9:41 am
Posts: 1
I don't think there's any way to do this with Hibernate mappings. However, I guess you could use some custom code e.g.:

private Map<String, Event> titleEventMap;

public void setEvents(Map<Event> events) {
this.events = events;
for (Event e: events) {
// titleEventMap is an instance variable
titleEventMap.put(e.getTitle(), e);
}
}

public Map<String, Event> getTitleEventMap() {
return titleEventMap;
}


Top
 Profile  
 
 Post subject: Thank you.
PostPosted: Thu Mar 02, 2006 5:46 pm 
Newbie

Joined: Thu Mar 02, 2006 4:26 am
Posts: 2
Thank you.
But in this case I should iterate all selected entities. Too long for me...


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

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.