I am trying to retrieve json data from SQL however ID is not being returned at all. Here is my code:
@Entity
@Table(name="Customer")
@SequenceGenerator(name="yourSequenceGenerator", initialValue=1, allocationSize=50)
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "ID")
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
public List<Customer> addAllCustomers(){
entityManagerFactory.createEntityManager();
TypedQuery<Customer> query = entityManager.createQuery("SELECT e FROM Customer e", Customer.class);
List<Customer> resultList = query.getResultList();
return resultList;
}
@POST
@Produces(MediaType.APPLICATION_JSON)
public void getProfile(@QueryParam("name") String name,
@QueryParam("surname") String surname
)
{
entityManager.getTransaction().begin();
c.setContactName(name);
c.setSurname(surname);
entityManager.persist(c);
entityManager.getTransaction().commit();
entityManager.close();
entityManagerFactory.close();
}
Result
[{"contactName":"bartekwsk","surname":"ss"}]
I can write and read to database, only ID is not working