I have in an objectdb file 10 Entity Classes with some data in each (Athlete, Trainer, Stadium etc)
This is the code I use to retrieve all Managed Types and data for the Athlete class
Metamodel metamodel = em.getMetamodel(); Set<ManagedType<?>> allManagedTypes = metamodel.getManagedTypes(); for(ManagedType o : allManagedTypes) { String strTmpClass = o.toString().replace("Type ", ""); // Getting the object name for the SELECT String tmpQuery = "SELECT s FROM " + strTmpClass + " s"; // This works for all classes TypedQuery<Athlete> query = em.createQuery(tmpQuery, Athlete.class); // I want to avoid this List<Athlete> results = query.getResultList(); for(Athlete result : results) { System.out.println(result.Code + ", " + result.Name + ", " + result.Surname + ", " + result.CountryOfOrigin + ", " + result.Genre); } }
Is there a way to get data of all classes without writing down 10 different queries (i.e. using the for loop)?
I tried to use TypedQuery<Object> instead of TypedQuery<Athlete> but had casting issues