I have mounted a API in jersey , create a class that has the methods > REST and it is working, input data from the client POSTMAN where GET , POST , PUT , and DELETE work, send POST or PUT are executed correctly, but after having sent these methods the GET it returns the data without updating.
To be able to see the changes with the GET I have to download the server, I do not know where to check, attached Bean where the REST service was created:
@Stateless
@Path("/docente")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class DocenteFacadeREST extends AbstractFacade<Docente> {
@PersistenceContext(unitName = "ApiSilaboPU")'
private EntityManager em;'
public DocenteFacadeREST() {
super(Docente.class);
}
@POST
@Override
public void create(Docente entity) {
super.create(entity);
}
@PUT
@Path("{id}")
public void edit(@PathParam("id") int id, Docente entity) {
super.edit(entity);
}
@DELETE
@Path("{id}")
public void remove(@PathParam("id") int id) {
super.remove(super.find(id));
}
@GET
@Path("{id}")
public Docente find(@PathParam("id") int id) {
return super.find(id);
}
@GET
@Override
public List<Docente> findAll() {
return super.findAll();
}
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
protected abstract EntityManager getEntityManager();
public void create(T entity) {
getEntityManager().persist(entity);
}
public void edit(T entity) {
getEntityManager().merge(entity);
}
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
public List<T> findAll() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
public List<T> findRange(int[] range) {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
javax.persistence.Query q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0] + 1);
q.setFirstResult(range[0]);
return q.getResultList();
}
public int count() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
javax.persistence.Query q = getEntityManager().createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
}
}
My persistence unit:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="ApiSilaboPU" transaction-type="JTA">
<jta-data-source>poliSilabo</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
Teaching Class
@Entity
@Table(name = "docente")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Docente.findAll", query = "SELECT d FROM Docente d"),
@NamedQuery(name = "Docente.findById", query = "SELECT d FROM Docente d WHERE d.id = :id"),
@NamedQuery(name = "Docente.findByCedula", query = "SELECT d FROM Docente d WHERE d.cedula = :cedula"),
@NamedQuery(name = "Docente.findByNombre", query = "SELECT d FROM Docente d WHERE d.nombre = :nombre"),
@NamedQuery(name = "Docente.findByCategoria", query = "SELECT d FROM Docente d WHERE d.categoria = :categoria")})
public class Docente implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Size(max = 20)
@Column(name = "cedula")
private String cedula;
@Size(max = 50)
@Column(name = "nombre")
private String nombre;
@Size(max = 15)
@Column(name = "categoria")
private String categoria;
public Docente() {
}
public Docente(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCedula() {
return cedula;
}
public void setCedula(String cedula) {
this.cedula = cedula;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getCategoria() {
return categoria;
}
public void setCategoria(String categoria) {
this.categoria = categoria;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.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 Docente)) {
return false;
}
Docente other = (Docente) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "org.api.data.Docente[ id=" + id + " ]";
}
}