-->
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: Advanced associating issue
PostPosted: Tue May 08, 2007 9:55 am 
Newbie

Joined: Sun Dec 17, 2006 10:15 am
Posts: 6
Location: Prague
Hello,

I have these two tables in my DB model:

Code:
create table "LANGUAGE_TEXTS" (
  "TEXT_ID" number(10,0),
  "LANGUAGE_NAME" varchar2(2 byte),
  "TEXT" varchar2(4000 char),
  constraint "PK_LANGUAGE_TEXTS" primary key ("TEXT_ID", "LANGUAGE_NAME"),
  constraint "FK_LANG_TEXTS$TEXTS" foreign key ("TEXT_ID") references "TEXTS" ("TEXT_ID")
);

create table "TEXTS" (
  "TEXT_ID" number(10,0),
  constraint "PK_TEXTS" primary key ("TEXT_ID")
);

create table "USER_ROLES" (
  "ROLE_NAME" varchar2(50 byte), 
  "TEXT_ID" number(10,0),
  constraint "FK_USER_ROLES$TEXTS" foreign key ("TEXT_ID") references "TEXTS" ("TEXT_ID")
);


The first table holds localised texts for all locale specific objects in the application. The second one helps to associate the texts with the objects using TEXT_ID foreign key (because the LANGUAGE_TEXT table has composite primary key). The USER_ROLES table illustrates using of language texts. Note that TEXT_ID must be generated using Oracle sequence.

So I designed the following base of corresponding domain model entities:

Code:
@Entity
@Table (name = "LANGUAGE_TEXTS")
public class LanguageText {
  @EmbeddedId
  private LanguageTextPK id;
 
  @Column (name = "TEXT")
  private String text;
  ...
}

@Embeddable
public class LanguageTextPK {
  @Column(name = "TEXT_ID", nullable = false)
  private Long id;

  @Column(name = "LANGUAGE_NAME", nullable = false)
  private String languageName;
  ...
}

@Entity
@Table(name = "TEXTS")
@SequenceGenerator(name = "textIdGenerator", sequenceName = "SEQ_TEXTS")
public class Text {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO, generator = "textIdGenerator")
  @Column(name = "TEXT_ID", updatable = false)
  private Long id;
  ...
}

@Entity
@Table(name = "USER_ROLES")
public class UserRole {
  @Id
  @Column(name = "ROLE_NAME")
  private String name;

  @Column(name = "TEXT_ID")
  private Long textId;

  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @JoinColumn(name = "TEXT_ID", referencedColumnName = "TEXT_ID")
  @MapKey(name = "id.languageName")
  private Map<String, LanguageText> languageTexts;
  ...
}


Now, I need associate LanguageText and Text entities so that all will be correctly saved to database. I want only call session.save(userRole), that's all. But I can't find a way how to make it...

Note that the DB model is legacy and I can't change it.

Thank you very much for any suggestions.

Darbic

---

Hibernate version: 3.2.0

Name and version of the database you are using: Oracle Database 10.2 XE

JDBC driver: Oracle Thin JDBC Driver 10.1.0.5.0

_________________
Tomáš Klíma, Aiteq Ltd.
tomas.klima@aiteq.com | skype: tomas.klima | icq: 117-871-950 | www.aiteq.cz


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.