vaadin / starters

Issue repository for all the starter projects in https://vaadin.com/start
3 stars 0 forks source link

Remove AbstractEntity #78

Closed simasch closed 1 year ago

simasch commented 1 year ago

The AbstractEntity that is generate for master-detail is an anti-pattern

  1. equals shouldn't be implemented generally
  2. GenerateValue UUID is not JPA standard.

I would suggest to remove the AbstractEntity

Artur- commented 1 year ago

Why is it an anti-pattern? Why shouldn't equals be implemented? Why would it be better to put generic code in all entity classes?

simasch commented 1 year ago

If you want to use a Sequence per entity you have to put the id in the entity (that's the default case)

Why you must not want to implement equals and hashCode or how you should: https://thorben-janssen.com/ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate/

Artur- commented 1 year ago

If you do not implement equals for an entity and use it in e.g grid then it will not work as you would expect because of the requirement also specified in the linked page

// 2 managed entities that represent the same record need to be equal
e1 = em.find(MyEntity.class, id1);
e2 = em.find(MyEntity.class, id1);
Assert.assertTrue(e1.equals(e2));
simasch commented 1 year ago

@Artur- Yes, you are right with the Grid refreshItem would probably not work.

Artur- commented 1 year ago

Let's not do this as it won't work when you use entities in a component. Also we will add optimistic locking by default and that naturally goes into AbstractEntity