Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的休息时间一无所获_Java_Xml_Rest_Entitymanager - Fatal编程技术网

Java 我的休息时间一无所获

Java 我的休息时间一无所获,java,xml,rest,entitymanager,Java,Xml,Rest,Entitymanager,我有一个实体类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 Wor

我有一个实体类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 + " ]";
    }

}
我的WorkplaceFacaderest.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();
}
没有别的了

更新:
我错过了MySQL的jdbc驱动程序。加上这些之后,项目成功了

可能是您的JAX-RS服务未在web.xml或javax.ws.RS.core.Application的子类中注册吗

一种方法是在web.xml中设置应用程序路径:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd" version="3.0">
<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/rest/api/*</url-pattern>
</servlet-mapping>

路径“rest/api”只是一个示例,您也可以将其设置为根目录,但部署JAX-RS服务需要这种配置之一。

您确定
SELECT w FROM Workplaces w…。
是您想要的吗?不
select*…
?此外,您可以在工作场所编写
select w,其中w.spId=:spId
,但稍后将
@Column(name=“sp_id”)
DB:spId或sp_id中的列名是哪一个?您是否使用最新版本的Firefox,如果不是,您可以尝试使用它访问rest服务?调试的另一个选项是使用HttpClient,如本例中的JAX-RS客户端(),并设置断点来检查响应实体包含的数据。这是JPQL查询(),在对象级别使用属性名执行@列是一个注释,用于覆盖字段spId名称和数据库的默认映射。只需进行一次小检查即可排除这种可能性:尝试向REST方法添加一些日志记录。在调试之后,我发现我丢失了mySQL的JDBC驱动程序。这就是我的问题。
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd" version="3.0">
<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/rest/api/*</url-pattern>
</servlet-mapping>
@ApplicationPath("rest/api")
public class RESTConfig extends javax.ws.rs.core.Application{ }