-->
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.  [ 5 posts ] 
Author Message
 Post subject: Internationalization: mapping i18n descriptions
PostPosted: Tue Sep 02, 2003 3:47 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
I've searched the web and these forums but haven't found anything about internationalization.

Can anyone tell me if I can map a description property on an object to a single record in an i18n table dependent upon the user's locale?

e.g.:
Code:
class MyMultiLanguageDescription {
    private int ID;
    private int someData;
    private String description;
}


multi_language_object_table { ID:int, someData:int }

multi_language_i18n_table { ID:int, locale_language:char(2), description:varchar(50) }


the data might look like this for example:
Code:
multi_language_object_table:
1, 27
2, 6
3, 4

multi_language_i18n_table:
1, 'en', 'twenty seven'
1, 'fr', 'vingt sept'
1, 'de', 'zwanzig sieben'
2, 'en', 'six'
2, 'fr', 'six'
2, 'de', 'sechs'
3, 'en', 'four'
3, 'fr', 'quatre'
3, 'de', 'vier'


Is it possible to map straight to a String for the description or would I need to load a collection of descriptions?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 4:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You could do this through a UserType, where the UserType is aware of the current user and that current user's locale and appropriately loads the correct localized description.

The other option would be to map this using a Map keyed by the locale for each of the descriptions.
Code:
<class name="MyMultiLanguageDescription" table="multi_language_object_table">
    ...
    <map name="localizedDescriptions" table="multi_language_i18n_table">
        <key column="id"/>
        <index column="locale_language" type="locale"/>
        <element column="description" type="string"/>
    </map>
</class>


Top
 Profile  
 
 Post subject: Criteria for Associations of Associations of...
PostPosted: Tue Sep 02, 2003 8:21 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Okay, I've made classes that are mapped to views of my lookup data with the internationalized descriptions (i.e. duplicate record per language in the view) and I want to use the new Criteria support for associations in version 2.1 beta 2 to narrow down the list of values by language but the example in the new documentation only goes one level deep and only for one property.

What is the proper syntax for creating Criterias that are nested three levels deep and which must be repeated for more than one property?

I need to be able to specify the Expression.eq("language", "en") on a property on a Set one-to-many which is on a Map one-to-many which is on another Map one-to-many, how do I nest the calls to .createCriteria? And how do I do nest them so that I can do this more than once because I have three different Sets which I need to narrow down like this?

Thank-you very much.
Sincerely,
David


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 5:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
how do I nest the calls to .createCriteria?

Just do it! ie. call createCriteria() and the Criteria returned by the first createCriteria()


It meant to be all quite natural.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 3:30 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
Just do it! ie. call createCriteria() and the Criteria returned by the first createCriteria()


That is what I thought, however, either I'm doing something wrong, or it doesn't work from within a map to another map.

My code (broken down line by line so that I could easily see the failure point in the stack trace) is like so:
Code:
         criteria = session.createCriteria(WorksheetHeader.class).add(
               Expression.eq(WORKSHEET_ID, new Integer(worksheetID)));
         criteria = criteria.createCriteria("products");
         criteria = criteria.createCriteria("costFactors");
         criteria = criteria.add(Expression.eq("calculatedTypeOptions.language", language));
         criteria = criteria.add(Expression.eq("proratingTypeOptions.language", language));
         criteria = criteria.add(Expression.eq("descriptions.language", language));


The line: criteria = criteria.createCriteria("costFactors"); generates the following exception:
Code:
ERROR [web-9] (WorksheetService.java:132) - Could not load worksheet 14
net.sf.hibernate.QueryException: could not resolve property: products.costFactor
s [null]
        at net.sf.hibernate.persister.AbstractPropertyMapping.getPropertyType(Ab
stractPropertyMapping.java:33)
        at net.sf.hibernate.impl.CriteriaImpl.getClassForPath(CriteriaImpl.java:
205)
        at net.sf.hibernate.impl.CriteriaImpl.createAlias(CriteriaImpl.java:183)

        at net.sf.hibernate.impl.CriteriaImpl.createCriteria(CriteriaImpl.java:2
37)
        at net.sf.hibernate.impl.CriteriaImpl$Subcriteria.createCriteria(Criteri
aImpl.java:74)
        at com.fgl.ina.costestimation.services.WorksheetService.getWorksheetByID
(WorksheetService.java:122)
...


My mappings (abbreviated to relevent sections) look like this:
Code:
<hibernate-mapping>

   <!-- WorksheetProduct -->
   <class name="com.fgl.ina.costestimation.WorksheetProduct" table="worksheet_product">
      <id name="ID" type="integer" column="worksheet_product_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>

<!-- ... -->

      <map name="costFactors" table="worksheet_factor" lazy="false" cascade="all" order-by="worksheet_factor_id">
         <key column="worksheet_product_id"/>
         <index column="worksheet_factor_id" type="string"/>
         <one-to-many class="com.fgl.ina.costestimation.WorksheetFactor"/>
      </map>
   </class>

   <!-- WorksheetHeader -->
   <class name="com.fgl.ina.costestimation.WorksheetHeader" table="worksheet_header">
      <id name="worksheetID" type="integer" column="worksheet_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>

<!-- ... -->

      <map name="products" table="worksheet_product" lazy="false" cascade="all" order-by="worksheet_product_id">
         <key column="worksheet_id"/>
         <index column="worksheet_product_id" type="string"/>
         <one-to-many class="com.fgl.ina.costestimation.WorksheetProduct"/>
      </map>
   </class>

   <!-- WorksheetFactor -->
   <class name="com.fgl.ina.costestimation.WorksheetFactor" table="worksheet_factor">
      <id name="ID" type="integer" column="worksheet_factor_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
      <property    name="costFactorID"       column="cost_factor_id"       type="integer"/>

      <property    name="calculatedType"     column="calculated_type"       type="short"/>
      <set name="calculatedTypeOptions" lazy="false" cascade="none">
         <key column="cost_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.lookups.CalculatedTypeLookup"/>
      </set>

<!-- ... -->

      <set name="currencyTypeOptions" lazy="false" cascade="none">
         <key column="cost_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.lookups.CurrencyTypeLookup"/>
      </set>

<!-- ... -->

      <property name="proratingType"   column="prorating_type"    type="short"/>
      <set name="proratingTypeOptions" lazy="false" cascade="none">
         <key column="cost_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.lookups.ProratingTypeLookup"/>
      </set>

      <set name="descriptions" lazy="false" cascade="none">
         <key column="cost_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.CostFactorDescription"/>
      </set>
   </class>

   <!-- Cost Factor Description -->
   <class name="com.fgl.ina.costestimation.CostFactorDescription" table="cost_factor_description" mutable="false">
      <id name="costFactorID" type="integer" column="cost_factor_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
      <property name="language"    column="locale"      type="string"/>
      <property name="description" column="description" type="string"/>
   </class>
</hibernate-mapping>


Am I doing something wrong or can the Criteria not create a new Criteria on a map in a map?

Also, how would you "back up" one level if you had multiple high level branches you needed to set criteria on sub elements for?

Thank-you again for any assistance.
Sincerely,
David


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