alejandro-du / crudui

Automatically generate CRUD-like Vaadin views for any Java Bean
https://vaadin.com/directory#!addon/crud-ui-add-on
Apache License 2.0
85 stars 52 forks source link

Composite Key and CRUD #33

Closed avzlobin79 closed 5 years ago

avzlobin79 commented 6 years ago

Hello.I have problem.I can't update GRID with composite key if I change part of this key or all parts.It don't change.I see that to DB sending old composite key. What I must to do?DELETE,READ is working `


crud.getGrid().setColumns("title", "weaponInfo", "effectInfo", "chance");

    List<WeaponInfo> listItemsWeapon = weaponInfoRepo.readAll();

    formFactory.setFieldProvider("weaponInfo", new ComboBoxProvider<>("WeaponInfo", listItemsWeapon));

    List<EffectInfo> listItemsEffect = effectInfoRepo.readAll();

    formFactory.setFieldProvider("effectInfo", new ComboBoxProvider<>("EffectInfo", listItemsEffect));

@Entity

public class WeaponInfoEffectAppliance {

@EmbeddedId
private EffectWeaponKey id = new EffectWeaponKey();

@Column(name = "TITLE", unique = true)
@NotNull
private String title;

@ManyToOne
@NotNull
@MapsId("weaponInfoId")
private WeaponInfo weaponInfo;

@ManyToOne
@NotNull
@MapsId("effectInfoId")
private EffectInfo effectInfo;

@NotNull
@Column(name = "CHANCE")
@Min(value = 0, message = "The value must be positive")
private Double chance;

public WeaponInfoEffectAppliance() {
    super();
}

public WeaponInfoEffectAppliance(@NotNull String title) {
    super();
    this.title = title;
}

public EffectWeaponKey getId() {
    return id;
}

public void setId(EffectWeaponKey id) {
    this.id = id;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public WeaponInfo getWeaponInfo() {
    return weaponInfo;
}

public void setWeaponInfo(WeaponInfo weaponInfo) {
    this.weaponInfo = weaponInfo;
}

public EffectInfo getEffectInfo() {
    return effectInfo;
}

public void setEffectInfo(EffectInfo effectInfo) {
    this.effectInfo = effectInfo;
}

public Double getChance() {
    return chance;
}

public void setChance(Double chance) {
    this.chance = chance;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((chance == null) ? 0 : chance.hashCode());
    result = prime * result + ((effectInfo == null) ? 0 : effectInfo.hashCode());
    result = prime * result + ((id == null) ? 0 : id.hashCode());
    result = prime * result + ((title == null) ? 0 : title.hashCode());
    result = prime * result + ((weaponInfo == null) ? 0 : weaponInfo.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    WeaponInfoEffectAppliance other = (WeaponInfoEffectAppliance) obj;
    if (chance == null) {
        if (other.chance != null)
            return false;
    } else if (!chance.equals(other.chance))
        return false;
    if (effectInfo == null) {
        if (other.effectInfo != null)
            return false;
    } else if (!effectInfo.equals(other.effectInfo))
        return false;
    if (id == null) {
        if (other.id != null)
            return false;
    } else if (!id.equals(other.id))
        return false;
    if (title == null) {
        if (other.title != null)
            return false;
    } else if (!title.equals(other.title))
        return false;
    if (weaponInfo == null) {
        if (other.weaponInfo != null)
            return false;
    } else if (!weaponInfo.equals(other.weaponInfo))
        return false;
    return true;
}

@Override
public String toString() {
    return "(" + title + ")";
}

}

`

alejandro-du commented 5 years ago

This is likely to be a bug in your crud listener implementation. Are you able to provide a minimal project so I can reproduce the issue?

alejandro-du commented 5 years ago

Closing this for now. If you have questions regarding the component usage, please let's use the forum and only open an issue here if you are sure the problem you face is a defect in the component and not in your code.