Forum: Building VoltDB Applications

Post: Insert Master-Detail in a single transaction

Insert Master-Detail in a single transaction
Jan 30, 2014

It might just be that I am not able to find the necessary documentation to do this.

I am wondering, how do I insert records across multiple tables within a single transaction.

For example, let's assume I am trying to insert the details of an order. An order will contain 1 or more order line items, and it could also contain multiple shipping addresses.

How can I insert the order into the ORDER, line items into ORDER_LINE_ITEMS, and order shipment information into ORDER_SHIPMENT/ORDER_SHIPMENT_LINE_ITEMS as a single transaction ?

For most other DBs, I can wait until I have completed inserting all the rows into all the tables, and then commit it in as a single transaction. Is that possible ?

Thanks for your help
Jan 30, 2014
VoltDB does not support external transaction control. All transactions must be a single-round trip between the client and the server. This is one of the ways VoltDB achieves class-leading performance. To use transactional logic, or just to bundle inserts, you need to use stored procedures, either in Java or in Groovy (4.0).

Jan 30, 2014
So how do I pass a complex object to a VoltDB procedure ? Can I pass say an Order POJO which contains all the necessary details and line items, and then ensure that voltdb has the custom POJO available in it's classpath so as to be able to iterate through the line items and perform the inserts ?

Something like

public long run(Order order) {

public class Order {
   List<OrderLineItem> lineItems;
   List<OrderShipment> shipments;

public class OrderLineItem {}

public class OrderShipment {
  List<OrderLineItem> shipmentLineItems;

Or do i have to pass in say a VoltDB table for the line items with rows containing the details for the inserts that need to be performed.

For example

public long run(long orderId, VoltTable lineItems, VoltTable shipments, VoltTable shipmentLineItems) {
Jan 30, 2014
VoltDB only knows how serialize a specific set of types.

I believe the list is:
byte, short, int, long, double, Byte, Short, Integer, Long, Double, String, byte[], java.util.Date, java.sql.Date, java.sql.Timestamp, BigDecimal, VoltTable.
It can also serialize arrays of any of these types, including byte[][].

So yes, the second suggestion would work and the first would not. You can also serialize a POJO to a byte[] in your client and deserialize it in the procedure. That's a possible workaround as well. Just keep in mind that java built-in serialization is not the zippiest.
Mar 3, 2014
Hi, Could you help with information?
Is the VoltTable can be passed to the stored procedure from .Net Client,
As there are no such class in .net client, only VoltDB.Data.Client.Table, with no constructors defined.