Hi,
I have a legacy table that looks like this:
Code:
CREATE TABLE legacy (
id INTEGER NOT NULL,
foo_01 VARCHAR(30) NULL,
foo_02 VARCHAR(30) NULL,
foo_03 VARCHAR(30) NULL,
foo_04 VARCHAR(30) NULL,
foo_05 VARCHAR(30) NULL,
bar_01 VARCHAR(30) NULL,
bar_02 VARCHAR(30) NULL,
bar_03 VARCHAR(30) NULL,
bar_04 VARCHAR(30) NULL,
bar_05 VARCHAR(30) NULL
);
and I would like to map it to a Java class that looks like this:
Code:
public class FooBar {
private Long id;
private List<String> foos;
private List<String> bars;
...
}
The lists foo and bar might be of length 0..5, and if they are shorter than 5, then the unneeded columns in the table are set to SQL NULL. For instance, if foo.size() == 2 then foo_03, foo_04, and foo_05 will be set to null for that row in the legacy table.
I expect this is a common pattern that we have to deal with when mapping an object oriented model to a legacy database, but I haven't been able to find the answer in
Hibernate In Action, or on the Hibernate web site, or using Google. If the answer is already somewhere on the web and I'm just not finding it, I apologise for wasting everyone's time with this question, but I'd still really appreciate a pointer to the information!
Thanks!
-Jonathan