Vaadinversion: 14.4.1
spring-boot-starter-parent: 2.2.10RELEASE
I have two items in my grid. These two items looks like:
Kontakt{id=11657f9e-c4f4-414f-aab2-618252db9b06'vorname='test1'...
Kontakt{id=8da74f38-2072-4fb0-8c74-aede661f02b5'vorname='test'...
But the grid only displays only one items and so oft like the "itemslist.size()"
Also they react as “one row”. So I can like on the first and both get selected.
These are my @Entity(s)
@Entity
@Table(name = "std_kunde")
@Data
public class Kunde extends Kontakt {
public Kunde() {
super();
}
@Override
public String toString() {
return super.toString();
}
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
public abstract class Kontakt extends BasicEntity {
private String vorname;
private String name;
...
public Kontakt() {
super();
}
@Override
public String toString() {
return "Kontakt{" +
"id=" + getId() + '\'' +
"vorname='" + vorname + '\'' +
...
'}';
}
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
public abstract class BasicEntity {
@Id
@GenericGenerator(name = "id_generator", strategy = "....KeyGenerator")
@GeneratedValue(generator = "id_generator")
@Column(length = 128)
private String id;
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "create_date")
private Date createDate;
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modify_date")
private Date modifyDate;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "basicEntity")
private List<Anhang> anhangList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "basicEntity")
private List<Notiz> notizList;
public BasicEntity() {
anhangList = new ArrayList<>();
notizList = new ArrayList<>();
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(Object o){
if(null == o)
return false;
if(!(o instanceof BasicEntity))
return false;
BasicEntity b = (BasicEntity) o;
return b.getId().equals(this.getId());
}
}
And also the Grid code
@Autowired
private KundeService kundeService;
private Grid<Kunde> g;
public Dashboard() {
g = new Grid<>(Kunde.class);
g.addColumn(Kunde::getVorname).setHeader("Vorname");
g.setSizeFull();
setSizeFull();
add(g);
}
I tested to build a Grid based upon an other entiy and it worked like it should. Its like the first time I have this behaivor but I dont know how actually to debug it…
This is the @Entity
(Notiz) which works like expected.
UI-Code
private Grid<Kunde> g;
private Grid<Notiz> n;
public Dashboard() {
g = new Grid<>(Kunde.class);
g.addColumn(Kunde::getId).setHeader("ID");
g.addColumn(Kunde::getVorname).setHeader("Vorname");
g.setSizeFull();
n = new Grid<>(Notiz.class);
n.addColumn(Notiz::getId).setHeader("ID");
n.addColumn(Notiz::getTitel).setHeader("Titel");
n.setSizeFull();
setSizeFull();
add(g,n);
}
@PostConstruct
private void loadValues(){
g.setItems(kundeService.findAll());
n.setItems(notizService.findAll());
}
@Entity
@Table(name = "ld_notiz")
@Data
public class Notiz extends BasicEntitySystemFeatures {
private String titel;
@Column(length = 5000) //TODO
private String content;
private boolean abgeschlossen = false;
@Enumerated(EnumType.STRING)
private NOTIZ_TYP notizTyp;
public enum NOTIZ_TYP {
NOTIZ,
ERINNERUNG
}
@ManyToOne
private BasicEntity basicEntity;
public Notiz() {
super();
}
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
public abstract class BasicEntitySystemFeatures {
@Id
@GenericGenerator(name = "id_generator", strategy = "...KeyGenerator")
@GeneratedValue(generator = "id_generator")
@Column(length = 128)
private String id;
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "create_date")
private Date createDate;
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modify_date")
private Date modifyDate;
public BasicEntitySystemFeatures() {
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(Object o){
if(null == o)
return false;
if(!(o instanceof BasicEntitySystemFeatures))
return false;
BasicEntitySystemFeatures b = (BasicEntitySystemFeatures) o;
return b.getId().equals(this.getId());
}
- Below the screenshot. On top the notworking entity
Kunde
and on bottom the working entityNotiz