-->
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: Maping of (Hash)Maps
PostPosted: Sun Nov 13, 2005 8:16 am 
Newbie

Joined: Sun Nov 13, 2005 7:36 am
Posts: 6
I would like to persist a class A, containing a HashMap m, containing strings. The use case is a really simple contsruction:
Code:
public class A {
Map m = new HashMap();
Long id;
...
  public  string getStrForMapId (Integer key) {
    return (String) m.get (key);
  }
  public static A[] findAcontatingStr (string str) {
     //query the DB
  }
}


If I try to persist it exactly this way, the mapping itself is fine: hibernate creates two tables. But the problem is findAcontatingStr method, as map's elements are not available in HQL, i.e. I can't do something like
Code:
"select A from A where A.m.elements() = :str"

And if I created a composite-element class containg just a string, the HQL query would be possible, but Hibernate would create three tables instead of 2. This workaround looks to me really ugly, as I have to produce one unnecessary class, and one unnecessary table.

Do I miss the proper way of solving this use case with Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 6:31 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Please show your mapping.
Then somebody may be able to help you!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 1:17 pm 
Newbie

Joined: Sun Nov 13, 2005 7:36 am
Posts: 6
hhuber wrote:
Please show your mapping.
Then somebody may be able to help you!


Thanks for trying to help! The mapping in the first (prefferable) case is really trival:

Code:
<map
            name="m"
            lazy="false"
            sort="unsorted"
            cascade="all"
        >

            <key
                column="id"
            >
            </key>

            <index
                column="LANGUAGE_ID"
                type="int"
            />

            <element
                column="TRANSLATION"
                type="string"
                not-null="false"
                unique="false"
            />

     </map>

In the query I would like to match the column 'TRANSLATION'.


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.