-->
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: dynamic mapping of column to field
PostPosted: Wed Apr 16, 2008 2:18 pm 
Newbie

Joined: Wed Apr 16, 2008 1:52 pm
Posts: 1
Location: Moscow, Russia
Hi,

I have a problem with mapping to legacy database. The database contains a number of dictionary tables with localized data:
Code:
table group_types (
    id bigint not null,
    icon_id bigint not null, // some foreign key
    en_US varchar(255), // english
    de varchar(255), // german
    es varchar(255), // spanish
    /// etc
)



I also have a hierarchy of Dictionary classes:

Code:
@MappedSuperclass
public abstract class Dictionary {
    private Long id;
    private String name;
    // getters and setters
}
@Entity
@Table(name="group_types")
public class GroupType extends Dictionary {
    @ManyToOne
    @JoinColumn(name="icon_id")
    private Icon icon;
    // more getters and setters
}


I'd like to map group_types table to a class GroupType and choose in runtime what locale column (en_US, en_UK, de, fr etc) to bind to name field.

I cannot use native queries, because I need to get correct localized name everywhere (I need EAGER fetch of group type in group, for example).

I see the only option (except changing the DB schema which is not possible): to put somewhere in Hibernate a column picker object that will be called from a query generator and will look something like this:

Code:
class LocaleColumnPicker {
    Map<String,String> columns = ...;
    public String getColumnName(String field) {
         if ("name".equals(field)) return LocaleProvider.getLocale().toString();
         return columns.get(field);
    }
}


I'm using Spring 2.5 + JPA (Annotations 3.3.0, EntityManager 3.3.1) + Hibernate 3.2.4 (Criteria API in some cases)

Has someone ideas, how I could do that?


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.