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.  [ 2 posts ] 
Author Message
 Post subject: Persisting Entites with multilingual text
PostPosted: Tue Apr 08, 2008 7:57 am 
Newbie

Joined: Wed Feb 01, 2006 10:45 am
Posts: 18
Location: Salzburg, Austria
hi all,

is there a recommended way in Hibernate to store entites with multi-lingual values. My naive approach is to have an entity A that references an entity B (@OneToOne) containing the text and the languageId (see code example below). Then i could have a simple join from entity A to the entity B just specifying the desired language (my Repository implementation will add the language string from the current user session)

Code:
FROM Country c JOIN FETCH c.text t WHERE t.language='de'


But in order to have multiple text (B) entities for the same id i'd have to add another identifier to make it unique. Again, starting from a naive point of view, i created a composite key using the id and the language property. but if i do so Hibernate wont generate any ids for me because if you generate an unique id you don't need a composite key any more (and i do understand this :))

Is there any other way i could make this work? I thought of using a "pre-persist" listener to set the id manually but i still want Hibernate to generate an id (!) because Hibernate can do this in a DB independent way. Although i was able to create a Id generator myself i was not able to set it. (IdentifierGenerator always returns an id of type Serializable)

I appreciate any suggestions or hints in this direction.

Code:
@Entity
public class Country {
    @Id @GeneratedValue
    private Long id;
   
    @OneToOne(cascade=CascadeType.ALL)     
    @JoinColumns({
        @JoinColumn(name="text_id",referencedColumnName="id"),   
        @JoinColumn(name="lang_id",referencedColumnName="language")})       
    private CountryText text;
   
    @Column(name="text_id",updatable=false,insertable=false)   
    private Long textId; // need only textId to reload text
    ...
}


Code:
@Entity
public class CountryText {
        private Long id;
        private String language;
        private String text;
}

_________________
greetings,
kris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 2:58 pm 
Newbie

Joined: Wed Feb 01, 2006 10:45 am
Posts: 18
Location: Salzburg, Austria
so... i took some time browsing the Hiberate FAQ and found following entry that is related to my problem at http://www.hibernate.org/117.html#A36

My question now is how do i implement this using JPA 1.0? Somehow i have the feeling that it is not possible.

I'd also appreciate any suggestions or patterns for reading multilingual text from the database using Hibernate/JPA?

thanks in advance

_________________
greetings,
kris


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