-->
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: @CollectionOfElements in twice @Embedded object possible?
PostPosted: Wed Jul 12, 2006 5:24 am 
Beginner
Beginner

Joined: Wed Oct 08, 2003 6:34 am
Posts: 29
Hi there,
I'm using the Hibernate tools to generate the database schema from my annotated classes, and I would like to have something as the following:

Code:
@Entity
public class Family
  {
  @Embedded
  @AttributeOverride(name = "defaultLocale", column = @Column(name = "title_defaultLocale", length = 25))
  private InternationalizedString title;
  @Embedded
  @AttributeOverride(name = "defaultLocale", column = @Column(name = "description_defaultLocale", length = 25))
  private InternationalizedString description;
  ...
  }

@Embeddable
public class InternationalizedString
  {
  @CollectionOfElements
  @MapKey(columns = {@Column(name = "locale", length = 25)})
  @Column(name = "string", length = 2500)
  private Map<Locale, String> strings;

  @Column(length = 25)
  private Locale defaultLocale;
  ...
  }


I've been able to override the defaultLocale attribute with @AttributeOverride as shown so I get different column names for title and description default locales, but for storing the strings Hibernate only generates a table named family_strings. Instead I would need the following table structure:

Code:
CREATE TABLE family
  (
  title_defaultlocale varchar(25),
  description_defaultlocale varchar(25)
  )

CREATE TABLE family_title_strings
  (
  family_id varchar(50) NOT NULL,
  string varchar(2500),
  locale varchar(25) NOT NULL,
  CONSTRAINT family_title_strings_pkey PRIMARY KEY (family_id, locale),
  CONSTRAINT family_title_fk FOREIGN KEY (family_id) REFERENCES family (id)
  )

CREATE TABLE family_description_strings
  (
  family_id varchar(50) NOT NULL,
  string varchar(2500),
  locale varchar(25) NOT NULL,
  CONSTRAINT family_description_strings_pkey PRIMARY KEY (family_id, locale),
  CONSTRAINT family_description_fk FOREIGN KEY (family_id) REFERENCES family (id)
  )


Is this possible?

Thanks in advance, best regards
Jose


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 12, 2006 9:05 am 
Beginner
Beginner

Joined: Wed Oct 08, 2003 6:34 am
Posts: 29
I've found the following post where Emmanuel suggest to use JoinTable:

http://forums.hibernate.org/viewtopic.php?t=954276

But I can't figure out how to use it. JoinTable seems to be supported in a CollectionOfElements attribute, but not in Embedded to override an attribute of the embedded class...


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.