I have an existing table/class for which I occasionally have extra information. I'd like to put the extra information into a separate table/class and associate it with the original class, without making any changes to the schema of the original table. Something like this:
Code:
class Char {
@Id
private int ID;
private String font;
private String size;
@OneToOne
private Style style;
}
class Style{
private boolean bold;
private boolean italic;
private boolean underlined'
}
What I'd like to see in the schema is:
Code:
Table Create Table
----------------------- ---------------------------------------------
Char CREATE TABLE `Char` (
`id` bigint(20) NOT NULL auto_increment,
`font` varchar(255),
`size` varchar(255),
PRIMARY KEY (`id`)
) ENGINE=InnoDB
Style CREATE TABLE `Style` (
`id` bigint(20) NOT NULL,
`bold` tinyint(1),
`italic` tinyint(1),
`underlined` tinyint(1),
PRIMARY KEY (`id`)
CONSTRAINT `FK89B773C384085057` FOREIGN KEY (`id`) REFERENCES `Char` (`id`)
) ENGINE=InnoDB
It seems clear to me that this can work in terms of the SQL, and it's advantageous to me to not have to change the schema of the existing table (there's also a savings if only a small percentage of Chars have Styles).
I've been looking through many, many examples of unidirectional on-to-one mappings and can't see how to do this, or even whether it can be done.
Thanks in advance for any replies.
Michael