Example usage for javax.persistence PersistenceException getClass

List of usage examples for javax.persistence PersistenceException getClass

Introduction

In this page you can find the example usage for javax.persistence PersistenceException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:controllers.ParameterController.java

public Result addParameter() {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Parameter not saved, expecting Json data");
        return badRequest("Parameter not saved, expecting Json data");
    }/*from  w w w.  j  a v  a2s . co m*/

    //Parse JSON file
    long serviceId = json.findPath("serviceId").asLong();
    long indexInService = json.findPath("indexInService").asLong();
    String name = json.findPath("name").asText();
    String dataRange = json.findPath("dataRange").asText();
    String rule = json.findPath("rule").asText();
    String purpose = json.findPath("purpose").asText();

    try {
        ClimateService climateService = climateServiceRepository.findOne(serviceId);
        Parameter parameter = new Parameter(climateService, indexInService, name, dataRange, rule, purpose);
        Parameter savedParameter = parameterRepository.save(parameter);

        System.out.println("Parameter saved: " + savedParameter.getName());
        return created(new Gson().toJson(savedParameter.getId()));
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println(serviceId);
        System.out.println(pe.getClass().toString());
        System.out.println("Parameter not saved: " + name);
        return badRequest("Parameter not saved: " + name);
    }
}