Hi all,
I am tryng to develop master-detail page, represented by two tables, based on Oracle scott/tiger schema (so, this is well-know Dept/Emps relationship). So, I have two JPA entities, representing two DB tables.
For both table’s ContainerDataSource, I am using
Viritin ListContainer:
https://vaadin.com/directory#!addon/viritin
which basically work with List. - exaclty what master Dept Entity @NamedQuery “findAll” returns , and @OneToMany relationship filed for details Employees also. So, Viritin;s ListContainer fits very hadny with what I already have in my entities - just perform findAll, or take relationship List and I am already have List for build ContainerDataSource for details (Emps) table
Now, about master-details synchronization:
Because I am working with detached entites, and PersistenceUnit is RESOURCE_LOCAL (app should work on Tomcat), for the @OneToMany annotation I am forced to use fetch=FetchType.EAGER. This way, I am able to have detail Employyes even in the detached mode. So, when user select/changes current row in the master (Depts) table, int the table’s ValueChangeListener, I am rebuild child ListContainer by simply taking @OneToMany List from selected Dept.
So far, so good.
But, wondering, whether this is the best approach for taking details entities LIst, considering CRUD operation on details table? Because, in that scenario, for master Dept, I am forced to maintain related Employeed List instance by myself. Each time when adding new deails Employee, I need to add new Employee instance to the corresponding List. I know, this is required by JPA also (maintain entity graph in memory in sync. with database model), and this is performance efficient (no need to perform JPA Query in order to take Emps details), but this is not esy task at all. For example, when deleting some Emps for particular Dept, , going to another one app page, and goind back to Dept/Emps page again, I am able to see in fact deleted employees for that master, so something goes wrong im memoty model, I am have hard to find bug somewhere The things are just becames complicated because of EntityManager.
merge()
behaviour - it returns _another _instance of just edited Employee entity,so I am forrced to _replace old one entity in the table;s Container with tha new instance
Because of that, would it be better (at least simpler) to use parametrized @NamedQuery ("
select o from Employees o where o.department =…"
) each time master Dept changes? Because it guaranties I will have correct Employee list each time user perform CRUD operation on detail employees table. And, after every CRUD operation, rebuild appropriate Container based on query result. At the same time, this have perfomanc cost.
What you are people doing, what is the best practice, and, is there any CRUD master/detal demo, which demonstrates the best techniques? it is simply strange that for a lot of tools/frameworks, there is one such example…or still exists?