This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes One to many insert with iBatis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "One to many insert with iBatis" Watch "One to many insert with iBatis" New topic

One to many insert with iBatis

Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3476

Consider these two tables: Order and OrderItem.
The relationship is one to many.
To save an order, two SQL command should be executed:
Insert a row in Order table (ORDER_ID is auto generated).
Insert a row in OrderItem table (OI_ID is auto generated and the primary key of the previous insert is needed in this command).
I'm trying to adopt iBatis and MySQL as the database.
The problem is I don't know how to get the PK of the first row in order to be passed to the second row?
Any ideas?
It is sorta covered in the JavaRanch Style Guide.
subject: One to many insert with iBatis
Similar Threads
Hibernate - id column of an entity as list-index column in another entity?
oracle sequence id
ejb 1.1 how to using ejb about one to many relationship?
Null Value in @JoinColumn
hibernate saving multiple hierarchy records