Original jpa request fetch multiple objects

I have a database with 4 tables:

company,staff,department,project

      

.Java company

@Entity
@Table(name = "company")
@SqlResultSetMapping(name = "COMPANY", entities = 
{
    @EntityResult(entityClass = Company.class),
    @EntityResult(entityClass = Staff.class)
})
...

      

GetEntity.java

EntityManagerFactory emf = Persistence.createEntityManagerFactory("GetEntityPU");
EntityManager em = emf.createEntityManager();

String query = "SELECT * 
                FROM company c 
                JOIN staff s 
                ON c.ID = s.companyID";
Query q = em.createNativeQuery(query, "COMPANY");
List<Object[]> list = q.getResultList();

      

From the above code, I can get all the data on behalf of the company and staff.

Now I want to get all data from any two tables:
maybe all data for the company, personnel tables OR all data for personnel, department tables

How should I control each object in my request?

I really have no idea how to do this.
Any ideas or helpful source link is appreciated.

+3


source to share


1 answer


Mapping request to bean can help you, check this: request to bean



0


source







All Articles