Usage

The benefits of using this method (instead of simply using the Java new keyword) are:

  • any services will be injected into the object immediately (otherwise they will not be injected until the framework becomes aware of the object, typically when it is persisted through the RepositoryService

  • the default value for any properties (usually as specified by defaultXxx() supporting methods) or from the value type itself will be set and the created() callback will be called.

An alternative idiom is to just new up the object and then use ServiceInjector domain service can be used to inject services into the domain object. Note though that no default values will be set on the created object.

Example

For example:

Customer cust = factoryService.detachedEntity(Customer.class);
cust.setFirstName("Freddie");
cust.setLastName("Mercury");
repositoryService.persist(cust);

See also:

  • The RepositoryService is often used in conjunction with the FactoryService, to persist domain objects after they have been instantiated and populated.