May be I just misunderstand something. I was reading "iBATIS in Action"
book and found the following statement there:
It is not unusual for an object model to include components that also
contain
child objects. For example, an Order object may contain a list or array
of Order-
Item objects that represent the items that were ordered.
Because the iBATIS framework is primarily a SQL mapping tool, it does
not
manage these sorts of relationships when updating the database. As a
result, this
functionality is something that must be handled in the data layer of
your application
rather than in iBATIS.
For example, I have the following class representing nodes of the tree:
public class TreeNode {
private long id;
private List<TreeNode> children = new ArrayList<TreeNode>();
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<TreeNode> getChildren() {
return children;
}
public void setChildren(List<TreeNode> children) {
this.children = children;
}
}
And I would like to insert it in table TREE_TABLE:
create table TREE_TABLE
(
ID NUMBER(10) not null,
PARENT_ID NUMBER (10) null,
constraint PK_ TREE_TABLE primary key (ID)
)
/
alter table TREE_TABLE
add constraint FK_ TREE_TABLE_REF_3_TAB foreign key (PARENT_ID)
references TREE_TABLE (ID)
/
The question is how do I configure sql map "treeInsert" in order to make
this code work:
TreeNode root = new TreeNode();
TreeNode child1 = new TreeNode();
TreeNode child2 = new TreeNode();
TreeNode child3 = new TreeNode();
root.addChild(child1);
root.addChild(child2);
child2.addChild(child3);
sqlMap.insert("treeInsert", treeRoot);
Best regards, Alexey Kalmykov
OpenWay
________________________________
From: Stephen Boyd [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 20, 2008 7:05 PM
To: [email protected]
Subject: Re: insert/update objects graph
There shouldn't be any problems with it. I do it all the time. Can you
give us an example of your scenario that doesn't seem to work?
On Wed, Feb 20, 2008 at 11:01 AM, Alexey Kalmykov
<[EMAIL PROTECTED]> wrote:
Hi all,
I am trying to evaluate iBATIS as an ORM solution for my project. I
really like the overall idea behind iBATIS and its approach to ORM. I
have a question about insert and update operations. I've been
successfully loading graph of objects using resultMaps. But as far as I
understand, I am unable to insert/update a graph of user-defined objects
*using only* iBATIS mapping. Am I right? If yes, was it an original
intention not to implement such feature or just there are some
difficulties in iBATIS design that prevents from doing it?
Actually, I hope that I am wrong and somehow I can insert/update a graph
of objects only using iBATIS mapping :)
Thank you in advance.