-->
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: Efficient N:N String Mapping
PostPosted: Mon Jun 29, 2009 3:20 pm 
Newbie

Joined: Mon Jun 29, 2009 3:16 pm
Posts: 1
Hi guys,

I want to do a N:N relationship to map these classes: Document and Word.
Something like this:

Word {
int id;
String word; //must be unique
int freq;
}

Document {
int id;
List<Word> words;
}


By default, the mapping would be something like:

table_word:
id integer (pk)
word varchar (unique)
freq integer

table_document:
id integer (pk)

table_document_word:
id_document integer
id_word integer

At application level, when I am dealing with those objects, first I process Documents discovering new words.
At this time, I don't know yet the word id, only the word string. But, as I want to have unique strings at table_word,
How can I map these classes?

One naive map approach will violate the table_word unique constraint when already persisted words are found in Document.
By performance reasons, I don't want to query words objects by the string value to discover if the object is already persisted to get the id.
Also, I believe that maintain one Map<String, Integer> in memory to map each string to an existing database id is not the best approach.

I would like a solution in the same fashion way that Mysql does with "on duplicated key update":
INSERT INTO table_word (word,freq) VALUES ('word_string_value',1) ON DUPLICATE KEY UPDATE freq=freq+1;

How you guys would solve this problem?

Thanks in advance,

Rodrigo.


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.