I have a very simple object graph that I want to store in a database using MyBatis. If I make a brand new object graph (a BatisNode with two details), how do I write code to be sure the child objects are created? Here are the details:
public class BatisNode {
protected int id;
protected List details;
protected String name;
//Constructor and getters.
}
public class BatisNodeDetail {
protected int id;
protected BatisNode parent;
protected String name;
//Constructor and getters.
}
Schema:
CREATE TABLE node ( node_id int auto_increment primary key, name varchar(255) ); CREATE TABLE node_detail( node_detail_id int auto_increment primary key, name varchar(255) );
Mapper:
INSERT INTO node ( name ) SELECT #{name}; SELECT node_id id, name FROM node WHERE node_id=#{id};