0

Code for the controller class which will return response:

@RestController
@RequestMapping("/ProcessInfo/1.0.0")
public class RestController {
@ApiOperation(value = "getdeployments", notes = "This REST API is used to get deployments")
    @GetMapping(value = "/getdeployments")
    private List<ActivitiProcessDeployment> getdeployments() {

        return ActivitiGetDeploymentRepository.getDeployment();
    }

Below are the two entity classes having one to one mapping.

 @Entity
@NamedQueries({@NamedQuery(name="ActivitiProcessDeployment.getDeployment", query="SELECT a.id,a.name,a.category,a.tenantId,a.deployTime,b.category,b.key,b.resource_name,b.version,b.deploymentId,b.diagramResourceName,b.description,b.id,b.hasStartFormKey,b.hasGraphicalNotation_,b.suspensionState,b.tenant_id_ FROM ActivitiProcessDeployment a INNER JOIN ActivitiProcessDefinition b ON a.id=b.deploymentId ORDER BY a.id")})
@Table(name="act_re_deployment")
public class ActivitiProcessDeployment implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Id
    @JsonProperty
    @Column(name="id_")
    private String id;

    @JsonProperty
    @Column(name="name_")
    private String name;

    @JsonProperty
    @Column(name="category_")
    private String category;

    @JsonProperty
    @Column(name="tenant_id_")
    private String tenantId;

    @JsonProperty
    @Column(name="deploy_time_")
    private Date deployTime;

    @JsonProperty
    @OneToOne( cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name="deploymentId", nullable=true)
    private ActivitiProcessDefinition activitiProcessDefinition;
    }

Another entity class

 @Entity
@Table(name="act_re_procdef")
public class ActivitiProcessDefinition implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @JsonProperty("process_def")
    @Id
    @Column(name="id_")
    private String id;

    @JsonIgnore
    @Column(name="rev_")
    private String rev;

    @JsonProperty
    @Column(name="category_")
    private String category;

    @JsonProperty
    @Column(name="name_")
    private String name;

    @JsonProperty
    @Column(name="key_")
    private String key;

    @JsonProperty
    @Column(name="resource_name_")
    private String resource_name;

    @JsonProperty
    @Column(name="version_")
    private String version;

    @JsonProperty
    @Column(name="deployment_id_")
    private String deploymentId;
    }

JPA repository which is extending crud repository and calling the named query which is declared in the entity class.

@Repository
public interface ActivitiGetDeploymentRepository extends JpaRepository<ActivitiProcessDeployment, Long> {

    public List<ActivitiProcessDeployment> getDeployment();

} 

The response I'm getting is:

    [
    [
        "1",
        "ExecutionTaskListener",
        null,
        "-1234",
        "2018-10-29T07:31:48.373+0000",
        "http://www.activiti.org/test",
        "myProcess",
        "ExecutionTaskListener.bpmn20.xml",
        "1",
        "1",
        "ExecutionTaskListener.myProcess.png",
        null,
        "myProcess:1:4",
        "f",
        "t",
        "1",
        "-1234"
    ],
    [
        "13",
        "multiinstance (1)",
        null,
        "-1234",
        "2018-10-29T07:31:49.901+0000",
        "http://www.activiti.org/test",
        "multiinstance",
        "multiinstance.bpmn20.xml",
        "1",
        "13",
        "multiinstance.multiinstance.png",
        null,
        "multiinstance:1:16",
        "f",
        "t",
        "1",
        "-1234"
    ],
    [
        "23",
        "testing",
        null,
        "-1234",
        "2018-10-29T07:31:50.591+0000",
        "http://www.activiti.org/test",
        "myProcess",
        "testing.bpmn20.xml",
        "2",
        "23",
        "testing.myProcess.png",
        null,
        "myProcess:2:26",
        "f",
        "t",
        "1",
        "-1234"
    ]
]

As shown in the above response I am getting only json values I mean only table values without column names. So, how to get json response mapped with response coresponding key.

ashok
  • 1,078
  • 3
  • 20
  • 63

1 Answers1

0

I am not quite sure what you are trying to do and what actually happens (and why it is even possible). But as you can see your JSON is not a list of ActivitiProcessDeployment but a list of string lists.

Your named query does not return ActivitiProcessDeployments but a list of column values. Without any named query and an interface like below:

public interface ActivitiGetDeploymentRepository
            extends JpaRepository<ActivitiProcessDeployment, Long> {
    public List<ActivitiProcessDeployment> findAllOrderById();
}

you might get better results. It would not be flat as your JSON but ActivitiProcessDefinition would be nested inside your ActivitiProcessDeployment.

And if you need to do projection see this question & answer .

pirho
  • 11,565
  • 12
  • 43
  • 70