Include columns from related table in JPA using ListAll()

62 views Asked by At

I have 2 related tables and i am wondering if it is possible to include other columns (like firstname and surname) from table no1 when i am calling the function ListAll() in table no2? I am using JPA with Session Beans (AbstractFacade) and JSF Pages. Thanks in advance :-)

Table No1

  CREATE TABLE cases (
  caseid INT AUTO_INCREMENT PRIMARY KEY, 
  category VARCHAR(32), 
  descript VARCHAR(512), 
  isDone TINYINT, 
  userid INT, 
  INDEX user_ind(userid), 
  FOREIGN KEY (userid) REFERENCES USERS(userid)
);

Table 2

    CREATE TABLE users (
    userid INT NOT NULL AUTO_INCREMENT,
    firstname VARCHAR(64) NOT NULL,
    surname VARCHAR(64) NOT NULL,
    telephone VARCHAR(12),
    email VARCHAR(64),
    
    PRIMARY KEY (userid)
);

Entity Controller

@Named(value = "caseController")
@SessionScoped
public class CaseController implements Serializable {
    
    @EJB
    CasesFacade casesFacade;
    
    @Inject
    CasesBean casesBean;
    
    public List<Cases> getAll() {
        return casesFacade.findAll();
    }
1

There are 1 answers

1
Adrian N. On

If i correct understand maybe the good idea will be unpack chosen columns/fields to custom DTO on level repository or in code.