0

I created a restful webservice using netbeans created a entity class from the database and restful web services from entity class using jpa but i used tomcat as my server now the post method below wont insert the following json into the database but when i use glassfish as my server it works. Do you think I am missing any dependencies ? How can I emulate the glassfish?

I am trying to insert

{
"acceptedGender":"both",
"price":123123.00,
"type":"apartment"
"vacantNum":13,
"hadID":4
}

I have the following dependencies:
javaee-api-7.0.jar
javax.ejb-api.jar
mysql-connector-java-5.1.42-bin.jar

 @POST
 @Override
 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 public void create(Students entity) {
    super.create(entity);
 }`

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "hatID")
private Integer hatID;
@Basic(optional = false)
@Column(name = "type")
private String type;
@Basic(optional = false)
@Column(name = "acceptedGender")
private String acceptedGender;
@Basic(optional = false)
@Column(name = "vacantNum")
private int vacantNum;
// @Max(value=?)  @Min(value=?)//if you know range of your decimal fields 
consider using these annotations to enforce field validation
@Basic(optional = false)
@Column(name = "price")
private BigDecimal price;
//    @OneToMany(cascade = CascadeType.ALL, mappedBy = "hatID")
//    private Collection<Reservation> reservationCollection;
@JoinColumn(name = "hadID", referencedColumnName = "hadID")
@ManyToOne(optional = false)
private HaDetails hadID;

public HaTypes(Integer hatID, String type, String acceptedGender, int 
vacantNum, BigDecimal price) {
    this.hatID = hatID;
    this.type = type;
    this.acceptedGender = acceptedGender;
    this.vacantNum = vacantNum;
    this.price = price;`

Or if you dont have a solution to my problem could you recommend any provider aside from aws(dont have the time to study the docker), openshift and jelastic that could deploy a glassfish restful webservice on cloud easily.

Jan
  • 13,738
  • 3
  • 30
  • 55
Christian
  • 23
  • 7
  • 1
    any error messages anywhere? – Jan May 29 '17 at 14:03
  • @Jan there arent any error messages its just it wont insert values in the database but when i use glassfish it inserts values into the database using the same code – Christian May 29 '17 at 14:07
  • did you check catalina.out? If it's not inserting into the DB, maybe your DB connection is not established - how to set this up properly would differ between glassfish and tomcat – Jan May 29 '17 at 14:07
  • @Jan i did check the catalina.out and the connection was established in the netbeans – Christian May 30 '17 at 13:24

1 Answers1

0

Glassfish is an application server, therefore it supports JAX-RS out of the box. Tomcat is just a web container and you cannot deploy a JAX-RS app and have it work without wiring it by yourself (see this: In which container do JAX-RS web services run?).

If you want to run a Jersey server inside tomcat, you will need to configure it in your application's deployment descriptor. You can see answers on the following posts if you need details:

ernest_k
  • 44,416
  • 5
  • 53
  • 99