I am having trouble displaying in MyBatis for Java and would really like to help. My class structure is as follows:
class Foo
{
int id;
Bar bar;
}
class Bar {
String x;
int y;
}
My table looks like this: that is, it is de-normalized from the class structure.
create table foo_bar (
id int,
x varchar,
y int
);
My operational insert can de-normalize the parameters (bar.x, bar.y).
<insert id="insert" parameterType="foo">
<![CDATA[
insert into foo_bar
(id, x, y) values
(#{x}, #{bar.x}, #{bar.y})
]]>
</insert>
So the problem is:
When I make my selection, I would like the resulting object to be an instance of Foo that has a reference to Bar.
I don’t think I can use a type handler, since this works on a single column, and the association does not make sense either, since “Bar” is not an object explicitly represented in the database through a foreign key relationship.
Can someone show me the recommended way to do this, please?
Thank!