1

I have entity items and units, items are related one to many in the unit, I have difficulty entering data into items, where items need a primary key on the unit, while I don't understand how Jcombobox works in getting primary keys or IDs.

item class entity

@Entity()
@Table(name = "item")
public class Item extends Record{   

    @Column(unique = false, nullable = false, length = 100)
    public String name;

    @Column(unique = false, nullable = false, length = 50)
    public double stock; // untuk menambah terus data jumlah  item dari supplier

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "unit_id")
    public Unit unit;

class unit entity

@Entity()
@Table(name = "unit")
public class Unit extends Record {

    @Column(unique = false, nullable = false, length = 100)
    public String name;
    @Column(unique = false, nullable = false, length = 100)
    public String description;
    
  @OneToMany(mappedBy = "unit", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH,
      CascadeType.REFRESH })
    private List<Item> item;

methode load data for combobox

 private void getUnitItem() {

        List EntityUnitItem = new Unit(databaseSession).all();
        for (Iterator iterator = EntityUnitItem.iterator(); iterator.hasNext();) {

            Model.Entity.Unit getUnitItem = (Model.Entity.Unit) iterator.next();
            cmbSatuanItem.addItem(getUnitItem.name);

        }
       
    }

how do you save one to many on the button?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
sarifsidik
  • 11
  • 1

0 Answers0