My REST API Return Nothing



I have a entity class Workplaces.java:



@Entity
@Table(name = "workplaces")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Workplaces.findAll", query = "SELECT w FROM Workplaces w"),
@NamedQuery(name = "Workplaces.findBySpId", query = "SELECT w FROM Workplaces w WHERE w.spId = :spId"),
@NamedQuery(name = "Workplaces.findByWorkers", query = "SELECT w FROM Workplaces w WHERE w.workers = :workers"),
@NamedQuery(name = "Workplaces.findByLatitude", query = "SELECT w FROM Workplaces w WHERE w.latitude = :latitude"),
@NamedQuery(name = "Workplaces.findByLongitude", query = "SELECT w FROM Workplaces w WHERE w.longitude = :longitude")})
public class Workplaces implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "sp_id")
private Integer spId;
@Basic(optional = false)
@NotNull
@Column(name = "workers")
private int workers;
@Basic(optional = false)
@NotNull
@Column(name = "latitude")
private float latitude;
@Basic(optional = false)
@NotNull
@Column(name = "longitude")
private float longitude;

public Workplaces() {
}

public Workplaces(Integer spId) {
this.spId = spId;
}

public Workplaces(Integer spId, int workers, float latitude, float longitude) {
this.spId = spId;
this.workers = workers;
this.latitude = latitude;
this.longitude = longitude;
}

public Integer getSpId() {
return spId;
}

public void setSpId(Integer spId) {
this.spId = spId;
}

public int getWorkers() {
return workers;
}

public void setWorkers(int workers) {
this.workers = workers;
}

public float getLatitude() {
return latitude;
}

public void setLatitude(float latitude) {
this.latitude = latitude;
}

public float getLongitude() {
return longitude;
}

public void setLongitude(float longitude) {
this.longitude = longitude;
}

@Override
public int hashCode() {
int hash = 0;
hash += (spId != null ? spId.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Workplaces)) {
return false;
}
Workplaces other = (Workplaces) object;
if ((this.spId == null && other.spId != null) || (this.spId != null && !this.spId.equals(other.spId))) {
return false;
}
return true;
}

@Override
public String toString() {
return "com.rest.api.Workplaces[ spId=" + spId + " ]";
}

}


The snippet of my WorkplacesFacadeREST.java



@Stateless
@Path("com.rest.api.workplaces")
public class WorkplacesFacadeREST extends AbstractFacade<Workplaces> {
@PersistenceContext(unitName = "com.rest_hiring_challenge_war_1.0-SNAPSHOTPU")
private EntityManager em;

public WorkplacesFacadeREST() {
super(Workplaces.class);
}

@GET
@Path("{id}")
@Produces({"application/xml", "application/json"})
public Workplaces find(@PathParam("id") Integer id) {
return super.find(id);
}

@GET
@Override
@Produces({"application/xml", "application/json"})
public List<Workplaces> findAll() {
return super.findAll();
}


I tried request http://localhost:8080/hiring_challenge/com.rest.api.workplaces/500015631. I know primary key id 500015631 exists in my mysql db's workplaces table. I also tried: http://localhost:8080/hiring_challenge/com.rest.api.workplaces/. The result page just shows:



This XML file does not appear to have any style information associated with it. The document tree is shown below.


and nothing else.


No comments:

Post a Comment