Creating new entity instances in specific bundles

If you pass arguments to the new operator, Gosu calls a specific constructor defined for that Java type. If there are multiple constructors, Gosu uses the number and types of the arguments that you pass to choose the correct constructor. For Guidewire business entities such as Policy and User, typical code passes no arguments to create the entity. If you pass no arguments, Gosu creates the entity in the current bundle. Using the current bundle is usually the best approach.

In special cases, pass a single argument with the new operator to override the bundle in which to create the new entity instance. Pass an existing entity instance to create the new entity instance in the same bundle. Pass a bundle to explicitly use for the new entity instance. The following table compares different arguments to the new operator.

Arguments to new operator

Example

Result

No arguments

new Note()

Constructs a new Note entity in the current bundle. Changes related to the current code submit to the database at the same time as any other changes in the current bundle. This approach is the typical approach for most programming contexts, such as rule set code or plugin implementation code. This approach requires that there be a current bundle.

In some programming contexts, such as batch processes and WS-I web service implementations, there is no automatic current bundle.

An entity instance

new Note(myPolicy)

Constructs a new Note entity in the same bundle as a given Policy entity instance. Changes to the Policy are committed to the database at the same time as the new note, and all other changes in the bundle.

A bundle

new Note(myPolicy.bundle)

Same as previous table row

See also