package org.academiadecodigo.enuminatti.hibernatebootstrap.associations.many2one;

import org.academiadecodigo.enuminatti.hibernatebootstrap.SaveUtil;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class ManyToOne {
    public static void main(String[] args) {
        SaveUtil<Category> saveUtil = new SaveUtil<>();

        try {
            Category vegetables = new Category("Vegetables");
            vegetables.addProduct(new Product("Potato"));
            vegetables = saveUtil.save(vegetables);

            System.out.println(vegetables);

            vegetables.addProduct(new Product("Potato"));
            vegetables = saveUtil.edit(vegetables);
            System.out.println(vegetables.getProducts());

            System.out.println(vegetables);
        } finally {
            saveUtil.close();
        }

    }
}
