简体   繁体   中英

Get data from 2 different tables using JPA jax-rs REST service

If I have one table named A_client, and another one named B_client. A_client has ID's and different status values, while B_client is holding personal data, such as name and adress.

How do I do this if I followed this guide?

Examples below to show you where I am

I have a A_Client.java that looks like this:

@Entity
@Table(name = "A_client")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "AClient.findAll", query = "SELECT e FROM AClient e"),
@NamedQuery(name = "AClient.findById", query = "SELECT e FROM AClient e WHERE e.Id = :Id"})

And I have a A_ClientFacadeREST that looks like this:

@Stateless
@Path("test")
public class AClientFacadeREST extends AbstractFacade<AClient> {

@PersistenceContext(unitName = "com.123_MavenProjectTest_war_1.0-SNAPSHOTPU")
private EntityManager em;

public AClientFacadeREST() {
    super(AClient.class);
}
@GET
@Path("id")
@Produces({"application/xml", "application/json"})
public List<AClient> findById() {
    List<AClient> results = em.createNamedQuery("AClient.findById", AClient.class)
            .setParameter("Id", 1)
            .getResultList();
    return results;
}

etc etc

How do I manage to get data from B_Client aswell as A_Client using REST?

只需在AClient实体中的表之间设置OneToOne关系

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM