-->
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.  [ 4 posts ] 
Author Message
 Post subject: Localized descriptions with HashMap
PostPosted: Tue Aug 03, 2004 11:07 am 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
Hi all,
Forgive me if this is answered elsewhere but I haven't found anything yet.

I have an object called House, house will have a HashMap of
descriptions.

The descriptions will be accessed with a locale object.

ie

Map map = house.getDescriptions();
System.out.println(map.get(Locale.EN));

Here comes the confusion.

1)There doesn't seem to be many examples of using a HashMap
to be found on the web.

2) Is this the way to do something like this or do I need to go using
a usertype.

3) Am I barking up completely the wrong tree. Is there
another way that people usually do this ?

4) Anyone got a bit of sample code that does something like this
using xdoclet for hibernate mapping file generation ?

5) I want to add a helper method to the class so I can do this.

System.out.println(house.getLocalizedDescription(Locale.FR,Locale.EN));

here is what I was thinking of doing to the House class

public String getLocalizedDescription(Locale locale, Locale default) {

a_ check to see if there is anything in the HashMap that matches the
locale specified.

b_ If there is then return it.

c_ If there isn't try the default.

d_ If there is anything there return it.

e_ See if there is anything there if so then return it.

f_ If all else fails return an empty string.

}

Is this a stupid idea ?


Bryan

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject: duh ....
PostPosted: Tue Aug 03, 2004 11:23 am 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
Ok maybe I'm a crazy optomist but pehaps all I need to do is this ,

/**
* @return Returns the descriptions.
* @hibernate.map cascade = "delete"
*/
public Map getDescriptions() {
return descriptions;
}

Am I living in dreamworld here ?

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 12:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I don't know about the xdoclet definitions, but I would think youd need more than that (like the index and the key at least).

Check out http://www.hibernate.org/hib_docs/reference/en/html/collections.html#collections-mapping


Top
 Profile  
 
 Post subject: ANSWER TO QUESTION RESOLVED
PostPosted: Wed Aug 04, 2004 1:44 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
This works fine, I am posting this in case anyone has the same problem.

/**
* @return Returns the summaryDescriptions.
* @hibernate.map cascade = "delete" table = "SUMMARY_DESCRIPTIONS"
* @hibernate.collection-key column="parent_id"
* @hibernate.collection-index type = "java.util.Locale" column = "LOCALE"
* @hibernate.collection-element type = "java.lang.String" column = "TEXT"
*
*/
public Map getSummaryDescriptions() {
return summaryDescriptions;
}

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.