Skip to main content

Hi,

 

I created a quite simple projection with an action ‘GetNextPartNo’ that has no parameters and returns a number. Model looks like

 

action GetNextPartNo Number {

   initialcheck none;

}

 

It is implemented in plsvc file as

 

FUNCTION Get_Next_Part_No___ RETURN NUMBER

IS

BEGIN

    RETURN Eng_Part_Master_API.Generate_Part_No();

END Get_Next_Part_No___;

 

I can deploy it to int-node but when I test it with postman I get 

 

{

    "error": {

        "code": "ODP_DESERIALIZATION_ERROR",

        "message": "Error while de-serializing contents."

    }

}


But this would mean that my json document would not fit to the model. But I have no body in my message which could be wrong as the action has no parameters.

 

Any hints?

Hi Heibde

Please try with ‘function’ keyword instead of ‘action’ in projection file. Usually action is used for a PLSQL procedure and function is used for PLSQL function which returns a value.

Best Regards,

Sameera. 


Hi Heinz,

When your action does not contain any parameters you need to specify and empty body using {}

See the post below on how to call state changes for example.

 

But as @Prabhath Sameera mentions its better to use a function in your case since this is a simple http GET request that does not change DB state. When using http GET along with function you don’t need to (actually you cannot) specify any payload in your request body. But one thing to keep in mind is that actions can have return values too. But they are typically used along with http POST since they could possibly change the DB state.

Note: I’m assuming that Eng_Part_Master_API.Generate_Part_No() does not change the DB state

Cheers,

/Rifki


Hi Rifki,

 

I already tried it with a body ‘{}’ in Postman before I raised this question. That did not work. But maybe it was a problem of Postman and Postman did not use the body?

With ‘function’ instead of ‘action’ it works. Even if the function is named ‘GetNextPartNo’ and it really returns a PartNo, it will change the DB as it fetches the next value from a sequence (and do some checks). So, it is important that a COMMIT is automatically done by the framework. Not sure if that is the case for GET-requests? 

 

I would prefere a POST to make it clear that DB is changed by this services. So, you think that ‘action’ will be ok but I should check why Postman maybe didn’t send a body with content ‘{}’. Maybe it was because of some Header parameters?

 

Best regards, Heinz


Hi Heinz,

If it’s only a Oracle sequence that increases, I don’t think we should consider it a “true” change in DB state. Moreover according to Oracle:

When a sequence number is generated, the sequence is incremented, independent of the transaction committing or rolling back...  

 

https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_6015.htm#SQLRF01314

 

So it seems like you don’t need to commit the transaction and therefore no need for action/POST?

 

/Rifki


Thanks a lot Rifki!