Groovy expression for assigning DB Sequence value to a String type attribute

You can use Groovy expression to default value for  Key attribute from a database sequence while you create new instance of an entity object. If you have access to my book Oracle ADF Real World Developer’s Guide, see page 76 for details or see the following blog from Timo Hahn  http://tompeez.wordpress.com/2011/09/02/using-groovy-expression-to-set-a-primary-key-with-a-sequence-number/

This post is just meant for sharing a simple tip that I learned today(Thanks to Steve Muench) for assigning database sequence value to a String type attribute. In case if you need to assign the sequence value to an attribute of type String in an entity object(yes, there are such use cases as well), you can add "as String" to the end of the Groovy expression and set it as default value for the entity attribute.

Example:
(new oracle.jbo.server.SequenceImpl("DEPARTMENTS_SEQ", adf.object.getDBTransaction())).getSequenceNumber() as String

Comments

Post a Comment