Cont. on jpa native query retrieve multiple entities
My database (testing)
company - ID {PK}, name staff - ID{PK}, name, companyID{FK} department - ID{PK}, name, companyID{FK}, staffID{FK} project - ID{PK}, name, staffID{FK}
First, I want to backup the
company
table.String query = "SELECT c.ID as companyid, c.name as companyname FROM company c"; Query q = em.createNativeQuery(query, "MAPPING"); List<CompanyDTO> list = q.getResultList(); Company.java @SqlResultSetMapping(name = "MAPPING", classes = { @ConstructorResult( targetClass = CompanyDTO.class, columns = { @ColumnResult(name = "companyid"), @ColumnResult(name = "companyname") }) }) ...
Second, I want to backup the
staff
table.String query = "SELECT s.ID as staffid, s.name as staffname, s.companyID as companyID FROM staff s JOIN company c ON c.ID = s.companyID"; Query q = em.createNativeQuery(query, "MAPPING"); List<CompanyDTO> list = q.getResultList(); Company.java @SqlResultSetMapping(name = "MAPPING", classes = { @ConstructorResult( targetClass = CompanyDTO.class, columns = { @ColumnResult(name = "staffid"), @ColumnResult(name = "staffname"), @ColumnResult(name = "companyID") }) }) ...
Now I don't want to fix my table and class. How do I control the ? from the following?
SELECT ... FROM ? List<?> list = q.getResultList();
Any help please...