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: Creating a Map with many-to-many relationships
PostPosted: Sat May 07, 2005 12:17 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
Hi,

I have the following situation: I'm using a table to store text values localized in various languages. This table is then referenced whenever a localized text value is needed in another table. For example, I have a "Category" object that needs a localized title and description:

public class Category
{
...
Map title;
Map description;
};

Each Map should contain the language code as a key and the localized text as value. I want Hibernate to generate and use the following table definitions:

CREATE TABLE localizedtext (
id BIGINT,
language VARCHAR(5),
text VARCHAR(255),
PRIMARY KEY (id, language)
)

CREATE TABLE categories (
...
title BIGINT, // tied to “id” in “localizedtext”
description BIGINT // tied to “id” in “localizedtext”

)

How do I set up my Hibernate mappings for “title” and “description”?

Many thanks,
Jen


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 1:30 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
The <dynamic-component> element allows a Map to be mapped as a component, where the property names refer to keys of the map.
Code:
<dynamic-component name="userAttributes">
    <property name="foo" column="FOO"/>
    <property name="bar" column="BAR"/>
    <many-to-one name="baz" class="eg.Baz" column="BAZ"/>
</dynamic-component>



Read chapter 5.1.12. : component, dynamic-component http://www.hibernate.org/hib_docs/refer ... -component

and chapter 7.5: Dynamic components http://www.hibernate.org/hib_docs/refer ... ts-dynamic

Let me know it this helps you solve your problem.
Vincent Giguère

_________________
Vincent Giguère
J2EE Developer


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.