How to save data in Master-Detail tables with seq PKs in Java? — oracle-tech

    Forum Stats

  • 3,702,032 Users
  • 2,239,549 Discussions
  • 7,835,720 Comments

Discussions

How to save data in Master-Detail tables with seq PKs in Java?

GadoGado Posts: 616 Blue Ribbon
edited May 2017 in Java Desktop Applications

Hello Experts,

I'm building a Sales Order application.

And now i'm stuck in how to save the sales Order.

I know how to insert records in a single database table ... but now i want to save in both tables.

I want to insert a record in the master SalesOrder table and the items in the detail SalesOrderItems at the same time.

The Primary keys in both tables are assigned using a database sequence so i don't know how to handle the relation between them

There is no way to know the SalesOrder (Master)'s PK to assign as a FK in the SalesOrderItems (Detail) table at the time i'm saving the data.

Is this possible?

Thank you for your time

Gado

Answers

  • eudriscabrera-JavaNeteudriscabrera-JavaNet Posts: 214 Bronze Badge
    edited May 2017

    Hi, You have to insert into the master table first and get the generated sequence for master inserted value. Then, you can use the value of the master to insert in the detail table. If you use an ORM you only need to insert the master and the ORM do the rest. Here, some resources: Best regards

This discussion has been closed.