-->
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.  [ 6 posts ] 
Author Message
 Post subject: multilingual db mapping mistery - request for help
PostPosted: Mon Mar 16, 2009 5:14 am 
Newbie

Joined: Wed Sep 17, 2008 10:51 am
Posts: 7
Hi.

I'd like to ask you for help to restore some mistery that I can't figure out for a long time:

I have a table MyTable with
integer id, string name
and a few localized columns that holds a localized strings.
Let they be name_fr,name_ru,.... each representing localized
name

I'd like to map some superclass MyClass and a buch of subclasses MyClass_ru, MyClass_en, each overriding the mapping of name property, mapping it to column appropriate for given language. I do want them to be instances of MyClass but I don't want "from MyClass" to return the subclasses instances, but only the MyClass ones.

Could you please help me with this? Or may be there is a more natural way to solve multilingual problem? The main requirement is to be able to bring a localized strings according to given locale, transparently from user...

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 9:56 am 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
You might call me crazy but, if myclass_en is a subclass of myclass. Then you are returning an instance of myclass. Just cast the object to myclass

MyClass newMyClass = (MyClass)myclass_en;

What is the special case where this does not work?

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 6:55 pm 
Newbie

Joined: Wed Sep 17, 2008 10:51 am
Posts: 7
Well, MyClass supposed to be not just superclass but a concrete mapped one that holds default mappings, and subclasses only override a field or 2...

That's the case... Returning a subclasses on "from MyClass" is ruining this intention :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 7:06 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I might have misunderstood you.

What you want to be able to do is make a query like

FROM MyClass

But instead of returning MyClass you want to return MyClassEn or MyClassFr depending on the configuration of the record in the database?

This is not possible that I know of unless you make seperate queries to the database specifically requesting each one. If I am understanding you correctly.

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 19, 2009 7:50 pm 
Newbie

Joined: Wed Sep 17, 2008 10:51 am
Posts: 7
Yes, that's what I wanted...
Anyway, I've found a kind of solution. MyClass shall not be declared as an Entity itself but rather be a superclass without concreate mapping itself. The mapped ones are subclasses like MyClassEn, MyClassFr, MyClassRu and we shall query against them, according to whatever locale we want.

Thanks,
Alex.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 19, 2009 8:46 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Yeah I think that is the best way to go about it, I am glad you found a solution.

_________________
Please rate my replies as I need points for all of my questions also.


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