OR mapping for java.util.Hashtables?

P

Philipp Leitner

Hi all,

I was just recently wondering how you (or, for that matter, any
standard OR mapping library like Hibernate) would map a
java.util.Collection datastructure to a relational database? I guess
there has to be a well-known approach to that problem - I just can't
find it for the for the life of me :)

Can anybody help me out on that? Precisely I need to map a
java.util.Hashtable to a HSQL database without using any specific OR
library.

thx in advance,
Philipp
 
O

Oliver Wong

Philipp Leitner said:
Hi all,

I was just recently wondering how you (or, for that matter, any
standard OR mapping library like Hibernate) would map a
java.util.Collection datastructure to a relational database? I guess
there has to be a well-known approach to that problem - I just can't
find it for the for the life of me :)

Different data structures would get mapped differently.
Can anybody help me out on that? Precisely I need to map a
java.util.Hashtable to a HSQL database without using any specific OR
library.


Store the keys somehow. Assume the keys have an ID.
Store the values somehow. Assume the values have an ID.

If you only need to store one Hashtable, you can create an SQL table to
represent that table with two columns. The first column is a reference to a
key id, and the second column is a reference to a value id. I.e. you're
storing a relationship between a key and a value.

If you need to store multiple hashtables, add a third column which is
the ID of the hashtable to which the relationship belongs.

- Oliver
 
P

Philipp Leitner

Oliver said:
Store the keys somehow. Assume the keys have an ID.
Store the values somehow. Assume the values have an ID.

If you only need to store one Hashtable, you can create an SQL table to
represent that table with two columns. The first column is a reference to a
key id, and the second column is a reference to a value id. I.e. you're
storing a relationship between a key and a value.

arg ... I knew there had to be a simple way that I just didn't see. You
opened my eyes there - thanks a lot Oliver.

/philipp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top