Search code examples
wso2-data-services-server

wso2 data services server - CRUD insert using a java generated GUID


I have an entity that requires a GUID for it's primary key. Ideally, I would like to use a java class to generate the GUID before adding the entity to the database, so that I can control exactly how the GUID is created.

Is it possible to delegate the key generation to a java class with WSO2 DSS? How?


Solution

  • you can try to generate the GUID within the SQL statement, using ORACLE (for example) functions. I guess you will success if the algorithm is not too complex. This way, your insert statement would look like:

    Insert into table (c1, c2, ..) values (functions for ID, v2,...)
    

    Although the best practice is to use a trigger before insert which call a database sequence to generate a new guid.

    You can also try to make a xslt transformation where you implement the algorithm to generate de guid. You would just have to perform the transformation before calling to dss.

    Hope it helps!