我有实体项和单元,单元中的项是一对多相关的,我很难将数据输入到项中,其中项需要单元上的主键,而我不明白jcombobox如何获取主键或id。
项目类实体
@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;
类单位实体
@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;
方法为组合框加载数据
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);
}
}
如何在按钮上保存一对多?
暂无答案!
目前还没有任何答案,快来回答吧!