0
How do I return a complete list of another class within a class? I need Patient.java to return (in the findALL that returns me in JSON) a list of all records in the Statuspaciente.java class, without restrictions. This is necessary because the front-end needs to know all the values (ID field and description) to fill a lookup for the user to select the value you want.
Follows the code:
@Entity
@Table(name="cad_paciente")
public class Paciente {
... (fields)
@ElementCollection
@CollectionTable(name="cad_status_paciente")
private List<StatusPaciente> getListaStatusPaciente;
public List<StatusPaciente> getListaStatusPaciente(){
TypedQuery<StatusPaciente> em = EntityManager.createQuery("SELECT x FROM cad_status_paciente x");
return em.getResultList();
}
--x--
public class StatusPaciente {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name="ds_status")
@Size(max=50)
private String status;
How do I do that? What’s the best way?
Hello, this is the English OS, please translate your question.
– renanvm
Thanks for the feedback, translated the text..
– Anderson Luiz Heckmann
the title was missing
– renanvm
Amended, thank you very much.
– Anderson Luiz Heckmann
Have you thought about creating your own @Query on your Repository?
– Nicolas Pereira
@Nicolaspereira Can you provide a simple example? Remembering that we need to return all Statuspaciente within the Patient’s JSON. It is possible?
– Anderson Luiz Heckmann
You can create your own @Query as if it were a query in a database, then within the query you make a Join Inner as you want
– Nicolas Pereira