Sculptor is not an one-size-fits-all product. Even though it is a good start for many systems, sooner or later customization is always needed. This guide will give you an understanding of the internal design of Sculptor and explains how to do changes for some typical scenarios. Some things can easily be changed with properties or AOP, while other things requires more effort, since you need to setup the development environment. Some changes are staightforward and some requires more in depth understanding of Eclipse Xtext and Xtend.

Table of Contents:

Sculptor Internal Design

Sculptors internal design
Figure 1. Internal Design of Sculptor

  1. The developer is using the DSL Editor plugin to edit the application specific model.btdesign, i.e. the source for the concrete model that is the input to the code generation process. Constraints of the DSL is validated while editing.

  2. When generating code is executed. It defines the flow of the code generation process.

  3. It starts with parsing the model.btdesign file using the Xtext DSL parser. Constraints of the DSL are validated.

  4. The DSL model is transformed into a model of the type defined by the sculptormetamodel.ecore meta model.

  5. Constraint validation is performed.

  6. The model is transformed again. Now it is actually modified to add some default values.

  7. Constraint validation again.

  8. Now the actual generation of Java code and configuration files begin. It is done with code generation templates written in Xtends template expressions. The templates extract values from the model and use Xtend extension methods and Java helper classes.

  9. Properties of technical nature, which don’t belong in the DSL or meta model, are used by the templates and the helpers.

Generator Properties

There are a many things that can be easily customized with properties. The default properties are defined in in sculptor-generator-configuration. You can override these properties by defining them in

Properties used in multiple within multiple Maven modules (sub-projects) of the same project can be defined in a single place - in This properties file is similar to (which is shipped with Sculptor) but it’s provided within your project.

Sculptor will look for properties in the following order:

  1. System properties (only intended for temporary tests)
  2. generator/ (provided in the Maven modules within you project)
  3. (optionally provided once within you project)
  4. (shipped with Sculptor generator library)

Project Nature

The main capabilities and responsibilities of the project is defined by the project.nature property. It is typically used to assign default values of more fine grained properties. E.g. the generated artifact of a presentation tier project is different from a business tier project.

The default project nature is business-tier. For a web project you specify:


A project may have several natures and the value of the property can be a comma separated list. E.g. to generate business and presentation tier in the same project you can specify:

project.nature=presentation-tier, business-tier

Framework Classes

You can replace the runtime framework with your own implementations by defining the class names in The naming convention is that the property key is the last part, starting with framework, of the default Sculptor framework class. E.g. to use your own base class for all domain objects:


Generic Access Objects

Sculptor provides generic access objects for operations such as findById, findAll, save, delete, etc. The implementation of these operations are located in the runtime framework. It is easy to replace those with your own implementation.

To replace all of them you define the following properties:


To replace a single implementation you define the class name like this:


If you need to replace the interface also:


When using Hibernate as JPA provider (which is the default) then the Hibernate specific implementations are used. For example findByCriteria is Hibernate specific. In case you want to use Hibernate as JPA provider, but stick to pure JPA implementations then you should add the following properties:


Database Product

MySQL, Oracle, PostgreSQL and HSQLDB-InMemory are supported out-of-the-box. You can select database with


Contribution of support for Apache Derby has been posted in the Forum

The database properties are only used for generating the DDL and some Hibernate settings. You can also change the default type mapping:


For parent child (one-to-many) relations the database can do cascaded delete of children when deleting parent. This is the default setting. It is possible to disable that and let Hibernate do the delete by setting the following property to false.


DDL script

There are two ways to generate database creation SQL script (DDL). Select between:

  1. Enable the hibernate3-maven-plugin hbm2ddl in pom.xml. The Maven archetype generates settings for it, but it is commented out. The default settings is to generate the DDL script every time in the build phase process-classes. You can change that by removing the <phase>process-classes</phase> in the execution section of the plugin definition in pom.xml. In that case you need to run the generation when needed with mvn hibernate3::hbm2ddl.

  2. Sculptor will generate DDL script if you add the following property in


The generated DDL script contains drop statements. In case you don’t wan’t to generate those you can define:


Individual classes may be omitted from the generated DDL. This can be useful to keep parts of the model that are works in progress from the DDL. To omit a class from the generated DDL, mark it with a “skipddl” hint:

Entity Roles {

	String roleName length="50" key;

By default, some of the system-generated attributes, such as version, createdBy, createdDate, are ordered at the end of each generated table in the DDL. This can be controlled via the systemAttributesToPutLast property:

# Attributes defined by system that should appear last in attribute listings, such as in DDL


Default cascade values can be defined for different types of associations. References between different modules have no default cascade value. all is default for references within the same module. You might want to change that to persist,merge if you don’t want delete to be propagated.

# default cascade values for aggregate references
# bidirectional one-to-many for aggregate reference
# default cascade values for references within same module
# bidirectional many-to-many
# bidirectional one-to-many
# unidirectional to-many
# unidirectional to-one


Mapping from simple types used in the DSL to generated types are defined with these properties:


java.lang types, such as String and Integer are not defined, since they have the same name in the DSL and the Java code.

You can add your own types also, e.g.


When you use your own classes, such as AccountNumber, you need to define the corresponding Hibernate user type.


If you define the above types you can use them directly in the DSL.

Entity Account {
  AccountNumber accountNumber
  - @Money balance

BasicType Money {
  Amount amount
  Currency currency

Another example, ShortString, which combines the database and java type properties.


The type of the automatically generated id attribute is defined as


Joda Date and Time API

It is possible to use Joda Time instead of the Java date and time classes.


Package Names

You can define the names of the generated packages.


You can also use subpackages.


Default Base Class

It is possible to define your own class to be use as extended base class for different types.

Note that extends can also be defined per domain object in model.btdesign:

Entity Movie extends @Media {

DataTransferObject SearchResponse extends {

Database Naming

There are a few configuration options for different naming strategies of database elements.

Convert camel-case to underscore in database names:


Foreign key column names ending with _ID:


ID column prefixed with table name:


File Header

You can define a header to be generated in java files. The java comments are added automatically, but you need to include the newline character.

javaHeader=Copyright line 1 \n\
 line 2 \n\
 line 3


Apache commons-langs ReflectionToStringBuilder is used for toString() in DomainObjects. You can define style with property:


JavaDoc of ToStringStyle describes the different formats.

You can also override this for individual DomainObject with hint:

ValueObject Foo {
    String aaa
    String bbb

equals and hashCode

For composite natural keys an inner key class is generated. If you prefer to skip this inner class you can define this property:


One drawback with not using key class is that findByKeys is not supported for composite keys.

Disable the generation of the ServiceContext

For some reason it might be required to switch off the generation of the ServiceContext - for example if you want to create a client without the created/updated functionality. In this case it can be done easily with setting a property value in the file:

# specifies if ServiceContext is to be generated

This turns off the generation of the ServiceContext.

Please note that in this case the auditable feature does not work or must be implemented manually. You can disable the generation of auditable with:


Null instead of NotFoundException

By default, some repository operations such as findById and findByKey throws NotFoundException if the query doesn’t find any matching result. You can use the following generator property to return null instead of throwing exception:


XML configuration for Spring

If you prefer Spring bean definitions in xml files instead of annotations you can use this property:


XML mapping for Hibernate

If you prefer hibernate mapping in xml files (hbm) instead of JPA annotations you can use this property:


Cache Provider

Cache provider settings are generated based on the property cache.provider.


There are some built in cache providers.

  1. EhCache - (default) settings are defined in ehcache.xml file, skeleton is generated
  2. JbossTreeCache - settings are defined as a JBoss mbean EJB3EntityTreeCache
  3. DeployedTreeCache - settings are defined as a JBoss mbean
  4. TreeCache - settings are defined in treecache.xml file
  5. Infinispan - (default cache provider for JBoss) no settings required because it’s pre-configured in JBoss AS 7

The choice also affects the cache usage attribute in the Hibernate mapping.

EhCache is the default cache provider, since it doesn’t require any additional configuration. JBoss Infinispan is recommended for (clustered) applications that require a transactional cache. Refer to JBoss documentation for information about how to configure Infinispan.


In case you don’t want validation annotations you can omit them with:


By default validation annotations are not generated for DataTransferObjects, but that can be enabled with property:


You can add your own validations or replace the implementation of the built in validators:

# built-in validation annotation

# built-in validation annotation (provider hibernate)

# validation annotation for Joda API

JPA annotation settings

If you prefer JPA annotations on getters instead of fields:


To generate annotations for database definition of column type:


JPA provider settings

If you prefer to use another JPA provider instead of Hibernate you can choose between EclipseLink, DataNucleus and OpenJPA.

To use EclipseLink add


Replace the hibernate properties and dependencies from pom.xml with



add the plugin to enhance the domain classes and the repository to resolve the dependencies

          <java classname=""
                classpathref="maven.compile.classpath" fork="true">
            <arg line="-loglevel FINE target/classes target/classes"/>

  <id>EclipseLink Repo</id>


If you want to use DataNucleus add


Replace the related hibernate properties and dependencies from pom.xml with



add the plugin to enhance the domain classes and the repository to resolve the dependencies


    <name>DataNucleus Repository</name>


To use OpenJPA add


Replace the hibernate properties and dependencies from pom.xml with



Add the Maven plugin to enhance the domain classes


Business Component without Persistence

You can create a business component that is not using JPA or MongoDB by defining generator property:


Remove persistence related dependencies in pom.xml:

If you are using the jpa.provider=none then you must add the classifier without-jpa to the sculptor-framework-test dependency:


The reason for using another jar file is that one of the test beans JpaTestBean should not be deployed.

Settings for Generated Diagrams

By default Sculptor generates a dot file (handled by Graphviz) for documentation purposes. This might not be needed for all projects. Please set the following property to drive the generation of this feature.

# specifies if umlgraph for Graphviz is to be generated

You can change colours for the generated diagrams.


# Highlight core domain with other colors

It is also possible to define color for individual elements using hint in model hint="umlgraph.bgcolor=D0D0D0". Hide elements using hint="umlgraph=hide".


Sculptor supports deployment as EAR or WAR (default). This is configured with the generator property deployment.type.

The design differences for each deployment type are as follows:

The Archetype Tutorial describes the steps how to convert WAR to EAR deployment (e.g. by setting deployment.type=ear). It also describes how to deploy in JBoss (e.g. by setting deployment.applicationServer=JBoss).

Deployment in Tomcat

By default Jetty is used to run the application. Instead of Jetty you can use Tomcat. Deployment in Tomcat requires that you do the following.

  1. Define the following property in in the business tier project:

  2. The Tomcat definition of the datasource is located in META-INF/context.xml in the WAR. This file is generated once, but you might need to adjust the settings.

  3. Copy the JDBC driver jar to Tomcat lib directory.

  4. Rebuild with mvn clean install in the parent directory.

  5. The WAR located in the target directory of the web project can be deployed in Tomcat.


JAXB annotations are by default only generated for DTOs. It can be turned on for other domain object types with these properties:



You should add the following property to your to avoid fully qualified class names in the XML of the REST representations. @XStreamAlias will be generated.



Scaffold operations are defined as a comma separated list.


Visibility of setters for not changeable attributes and references

By default the visibility is private for setter methods of not changeable attributes. Some tools might need visible setter methods and you can change the visibility with the following property. When you make these setters visible they will check that the value is not changed, once it has been set.


The visibility of setters for not changeable references are public. These setters will also check that the reference value is not changed, once it has been set. The reason for having the public setters is that sometimes the referred object is not available at construction time. Then it is possible to pass in null in the constructor and then afterwards assign the reference. If you would like to hide these setters you can use the following property.


Spring dispatcher servlet mapping

When generating the web client the default Spring dispatcher servlet mapping is /spring/*. To change it is a matter of changing a property:


Now the mapping will be /foobarbaz/*.

Spring Remoting Type

Spring remoting with RMI is used by default. The type of Spring remoting can be selected with properties in

# The type of remoting can be selected with

Hessian and HttpInvoker requires some additional configuration in web.xml, as described in Spring remoting documentation.

Spring Configuration

You can change the settings in It is runtime configuration of Spring.

Spring makes it possible to override bean definitions. The last definition wins. It is applicationContext.xml that is loaded first and it imports other configuration files. more.xml is imported last, which means that you can override generated bean definitions by specifying them in more.xml. This is also true for beans defined with annotations (@Repository, @Service, @Component). When running JUnit tests the corresponding file is more-test.xml.

This approach is not recommended, since it might be confusing to have multiple bean definitions. It is also easy to forget to change when something is renamed and that can have dangerous side effects. For testing or temporary modifications it might be an easy solution, but for permanent customization it is better to use one of the other alternatives presented in this article.

Change Generation Templates

You can customize the code generation templates using the Sculptor extension mechanism.

See Sculptor extension mechanism for details and steps on how to override templates (or transformations) in your project, or to extend Sculptor via cartridges.

You find the default templates in Everything starts in RootTmpl, which you also can intercept to add more templates or exclude some of the existing templates.

Another alternative is to setup the development environment and change the original templates and build a new version of sculptor-generator-core.


A very useful extension mechanism is available via the hint keyword in the model. It is possible to use a hint on almost any element in the model. It may contain any key/values, which can be used in Sculptor template extensions to customize the code generation.

For example, if you need to use a special database sequence for the ids of some entities. In the model you can use the hint:

Entity Person {

The corresponding template extension DomainObjectAttributeAnnotationTmplOverride.xtend:

class DomainObjectAttributeAnnotationTmplOverride
      extends DomainObjectAttributeAnnotationTmpl {

  @Inject extension DbHelper dbHelper
  @Inject extension Helper helper

  override String idAnnotations(Attribute it) {
      «IF domainObject.hasHint("idSequence")»

Several hints can be defined, separated with comma, and the hint may have a value or not.

String someAttribute hint="aaa=A,bbb,ccc"

Reference Application

When you customize Sculptor it is important that you have a representative reference application. It is used to verify the changes to the code generator. It must be big enough to span most of the design concepts you use, but still small enough to be supple.

When you do refactoring of the code generator it is recommended that you first do manual refactoring of the reference application. Keep that code base as a baseline. When you have changed the code generation the generated code should correspond to the manual baseline. Use a diff tool to compare the results.

The library example can act as a reference application if you haven’t developed one of your own. The source code is available in Sculptor GitHub repository:

Run the JUnit tests to verify that it works before you start changing.

It is convenient to use Eclipse project dependencies from the reference application to sculptor-generator-core. Then you can do changes in the templates and try them directly, without having to build with Maven. You can run the code generation directly inside Eclipse. In your reference application project, right click on Workflow.mwe2 and select ‘Run as MWE workflow’.

Constraint Validation

Check Language is used for validation of model constraints.

DSL Constraints

DSL constraints are validated directly when you edit the DSL file with the DSL editor (error highlight). DSL constraints are defined in and SculptordslChecks.chk in org.sculptor.dsl. If you change these you have to rebuild the plugins, but no other changes are needed.

Note that the constraints are both a help when editing the DSL and also a way to enforce certain design decisions.

Meta Model Constraints

Constraints of the ecore meta model is located in constraints.chk in sculptor-generator-core.


Xtend is used for model transformations.

DSL Model Transformation

Two meta models are used. One for the DSL, which is generated from the XText grammar. Another meta model is used by the code generation templates. They are rather similar, but still different. They serve different purposes, which motivates why two meta models are needed.

It would also be possible to replace the XText DSL meta model with some other, e.g. a graphical DSL implemented with GMF.

A transformation converts the DSL model to the code generation model. This transformation is implemented in DslTransformation.ext in sculptor-generator-core.

You can do a lot of powerful things in this transformation, without having to change code generation templates or its meta model. For example, the scaffold feature is implemented in the transformation. There is a property scaffold for DslEntity. It is like an ordinary Entity with attributes and references, but the DslTransformation automatically add Repository and Service with generic CRUD operations.

When you change the DSL, except for simple syntactic sugar, you often have to change the DslTransformation also.

Model Enrichment

There is one transformation that enrich the model with some useful default values. It is implemented in Transformation.ext. For example the id attribute of each persistent DomainObject is added by this transformation.

You can add more features to this transformation when needed. If it is not specific to the concrete syntax of the DSL, it is better to add features to this transformation than to the DslTransformation, since they will be available even if the concrete syntax is replaced by some other DSL.

GUI Transformation

A separate model is used for generation of the CRUD GUI. A transformation takes the domain model as input and and creates a model that is better suited for generation of the user interface. This transformation is located in GuiTransformation.ext

Customize the Transformations

The Sculptor extension mechanism can be used to customize the transformations. Follow either the steps in the overriding templates or transformations for a project or cartridges: reusable extensions to Sculptor, depending on how you want to package the extension.

For example, to skip automatic addition of uuid property in your project:

package generator

import org.sculptor.generator.transform.Transformation
import org.sculptor.generator.chain.ChainOverride

class TransformationOverride extends Transformation {


  override void modifyUuid(DomainObject domainObject) {

Meta Model

Input to the code generation is the model, which is structured according to the meta model sculptormetamodel.xcore. The meta model is defined with Xcore (an Xtext-based DSL for EMF models).

Business Tier Model (domain model)

Figure 2. Meta Model for the code generation model

If you have installed Eclipse Graphical Modeling Framework SDK (Ganymede update site) you will be able to edit the ecore file with a graphical editor, see Figure 2. Open the sculptormetamodel.ecore_diagram with the editor.

To prevent OutOfMemoryError when you use the graphical ecore editor you can add -XX:MaxPermSize=128m in eclipse.ini, which is located in the Eclipse installation directory.

When you add a totally new concept you have to add it to this meta model. When you change the meta model it is not enough to build with maven. First you must generate EMF model code.

  1. An EMF genmodel is created from the ecore model. Normally you don’t have to create a new genmodel, but when you do major changes you can remove the sculptormetamodel.genmodel and create a new from the ecore model using “File > New > Eclipse Modeling Framework > EMF Model”.
  2. Open the genmodel and right click on the top node. Select Generate Model. It generates Java code to src/main/java. It is safe to remove that code and generate it again if needed.

Now you can package the meta model with mvn install.

GUI Model

Sculptor doesn’t aim at implementing a general purpose GUI model that can be used for any type of GUI. We are focusing on the kind of CRUD GUI illustrated in the CRUD GUI Tutorial.

Figure 3. GUI Meta Model for the GUI parts of the code generation model

User Task

The model is arranged around User Tasks, The term UserTask is inspired by the presentation From User Story to User Interface. In this presentation it is described that:

Sculptor’s implementation with Spring Web Flow is that a UserTask corresponds to Flow. A conversation corresponds to a top level UserTask and its subtasks.

Code Generation Templates

Xpand Language is used for the templates.

The code generation starts in Root.xpt, which selects some course grained elements from the model and invokes other templates. In the templates you can access simple properties of the model objects and extension methods.

«DEFINE attributeTypeAndName FOR Attribute»
«getTypeName()» «name»

The extension methods are defined with Xtend in helper.ext. Some methods are implemented inside this file with the Expression Language and some delegate to Java helper classes.

Expression Language is also used in the templates to for example select elements from the model. | !r.many && (r.referenceType.metaType == BasicType))

How to

Some of the examples presented here are already implemented in Sculptor. It was convenient to add documentation and using real examples while implementing new features.

How to exclude generation

For some special cases the default generation might not be appropriate and it is desirable to handle the special case with manual code instead. For example, assume we have a complex domain object and we need to do the JPA/Hibernate mapping manually.

This can be nicely solved with the Aspect-Oriented Programming features in Xpand. It is described in Aspect-Oriented Programming in Xtend .

Define your advice in src/main/resources/generator/SpecialCases.xpt:

«IMPORT sculptormetamodel»
«EXTENSION extensions::helper»
«EXTENSION extensions::properties»

«REM»Skip createTable for Person«ENDREM»
«AROUND templates::db::OracleDDL::createTable FOR DomainObject»
    «IF name != "Person" -»
    	«targetDef.proceed() -»
    «ENDIF -»

«REM»Skip dropTable for Person«ENDREM»
«AROUND templates::db::OracleDDL::dropTable FOR DomainObject»
    «IF name != "Person" -»
    	«targetDef.proceed() -»
    «ENDIF -»

«REM»Skip DomainObject for Person«ENDREM»
«AROUND templates::db::DomainObject::domainObjectBase FOR DomainObject»
    «IF name != "Person" -»
    	«targetDef.proceed() -»
    «ENDIF -»

«AROUND templates::db::DomainObject::domainObjectSubclass FOR DomainObject»
    «IF name != "Person" -»
    	«targetDef.proceed() -»
    «ENDIF -»

Some of the generated artifacts can be controlled with properties in Look in for properties named For example, to skip generation of all junit tests:


How to customize persistence.xml

To adjust the JPA/Hibernate properties in persistence.xml you can add the following in SpecialCases.xpt:

«AROUND templates::jpa::JPA::persistenceUnitAdditionalProperties FOR Application»
    <property name="hibernate.show_sql" value="true" />
    <property name="hibernate.jdbc.batch_size" value="0" />

The above hibernate properties are useful when debugging.

How to use own Hibernate User Type

Hibernate User Type is powerful when you need conversion between domain and database representations.

You can define your own type in and also define its hibernateType. An example is to define a Time type like this:


This means that you can use Time in model.btdesign and @Type(type = "org.joda.time.contrib.hibernate.PersistentLocalTimeAsString") annotation is generated in the Java code.

How to change package names in the generated code

In the DSL you can define the root package for the Application. You can define the package of a Module, if the default is not satisfactory. The package name of individual Domain Objects can be specified, if the default is not appropriate.

Application Library {
    basePackage = com.mycorp.library

    Module common {
        basePackage = com.mycorp.common

        BasicType Address {
            String street
            String city

You can change the names of the subpackages to the module by defining properties in as described in packageNames.

How to add support for another database

Generation of database schema (DDL) is specific for different database vendors. To add support for your database you can do like this.

  1. In the application specific you define the database properties for your database. Note that the db.product value must be custom.

  2. Create a template for the DDL generation and locate it in templates/CustomDDL.xpt in the classpath, before the sculptor-generator-core jar.

OracleDDL.xpt is a template you can mimic.

Contribution of support for Apache Derby has been posted in the Forum

How to remove the circular dependency check

Define the following in


How to add custom generic access object

The Sculptor runtime application framework provides some useful generic AccessObjects, such as findById, findByQuery, save. It is likely that you need to add other generic AccessObjects.

To add a new generic AccessObject you can do like this. Assume you need an AccessObject that can evict from second level cache.

Evict AccessObject Interface:

 * This AccessObject evicts objects from second level cache.
public interface EvictAccess<T> {

     * Evict persistent objects. If {@link #setId(Long) id} is
     * not specified all objects of this class
     * be evicted.
     * @param persistentClass class of the persistent object
    public void setPersistentClass(Class persistentClass);

     * Evict a specific object. Set
     * {@link #setPersistentClass(Class) persistentClass}
     * also.
     * @param id the id of the object to evict
    public void setId(Long id);

     * Evict query cache with specified cache region
    public void setQueryCacheRegion(String queryCacheRegion);

    public void execute();


Evict AccessObject Implementation:

public class EvictAccessImpl<T> extends JpaAccessBase implements EvictAccess<T> {

    private Class persistentClass;
    private Long id;
    private String queryCacheRegion;

    public void setPersistentClass(Class persistentClass) {
        this.persistentClass = persistentClass;

    public void setId(Long id) { = id;

    public void setQueryCacheRegion(String queryCacheRegion) {
        this.queryCacheRegion = queryCacheRegion;

    public void performExecute() throws PersistenceException {
        if (queryCacheRegion != null) {
        if (persistentClass != null) {
            if (id == null) {
            } else {
                getHibernateSession().getSessionFactory().evict(persistentClass, id);


There are a few conventions for the AccessObjects that the templates are based on:

Define the interface and implementation in


The above addition of properties and classes means that you can use the evict AccessObject in your DSL model without any further changes of Sculptor, e.g.


Repository PlanetRepository {
    evict(String queryCacheRegion);
    evict(Class persistentClass);
    evict(Class persistentClass, Long id);

This would result in the following generated code in the Repository PlanetRepositoryBase:

public void evict(String queryCacheRegion) {
    EvictAccess<Planet> ao = planetAccessFactory.createEvictAccess();

public void evict(Class persistentClass) {
    EvictAccess<Planet> ao = planetAccessFactory.createEvictAccess();

public void evict(Class persistentClass, Long id) {
    EvictAccess<Planet> ao = planetAccessFactory.createEvictAccess();

The above is good enough in most cases, but it is also possible to define default parameters and return values for the RepositoryOperation, which means that you can skip those when using it in the DSL model. By this you can better support “convention over configuration”.

For example assume that evict(Class persistentClass) is the most used operation and you would like that a simple evict declaration corresponds to this. Then you need to implement a GenericAccessObjectStrategy

public class EvictAccessObjectStrategy
        extends AbstractGenericAccessObjectStrategy
        implements GenericAccessObjectStrategy {

    public void addDefaultValues(RepositoryOperation operation) {
        if (operation.getParameters().isEmpty()) {
            addParameter(operation, "Class", "persistentClass");

    public String getGenericType(RepositoryOperation operation) {
        DomainObject aggregateRoot = operation.getRepository().getAggregateRoot();
        String aggregateRootName = GenerationHelper.getPackage(aggregateRoot) + "." +
        return "<" + aggregateRootName + ">";

    public boolean isPersistentClassConstructor() {
        return false;


and register it in


To understand how to implement the strategy class you can have a look in GenericAccessObjectManager and the strategies implemented for the ordinary generic AccessObjects. It is located in sculptor-generator-core. These strategies are only used by the code generator. They are not used in runtime.

The above means that you can use evict without any parameters in the DSL model model.btdesign.

Repository PlanetRepository {

and the generated Repository method would look like:

public void evict(Class persistentClass) {
    EvictAccess<Planet> ao = planetAccessFactory.createEvictAccess();

For some rare special cases you might need to adjust the code generation template for the Repository, genericBaseRepositoryMethod in Repository.xpt.

You must place the genericAccessObjectStrategy class (EvictAccessObjectStrategy) in another library than your application project. It is used (only) by the code generator, and that is run before ordinary compilation, i.e. the class is not available in generate-sources phase if a clean has been done before.

How to add a transformation feature

Scaffold is a feature to be able to mark a Domain Object as scaffold and then automatically add some predefined operations (typically CRUD) to the corresponding Repository and Service. This is implemented in the transformation.

We add a boolean scaffold property to the DSL grammar for DslEntity. This is straightforward.

In the transformation DslTransformation.ext we add a Repository and Service if they doesn’t already exist. Operations are added to these, if they don’t exist.

scaffold(sculptormetamodel::DomainObject domainObject) :
    (domainObject.repository == null ?
        domainObject.addRepository() :
        null) ->
    domainObject.repository.addScaffoldOperations() ->
    ( | == ( + "Service")) ?
        null :
        domainObject.module.addService( + "Service")) -> | == ( + "Service")).

It is easiest to implement the actual creation and addition of model elements in Java. We implement the methods addRepository, addService and addScaffoldOperations in a Java helper class.

public static DomainObject addRepository(DomainObject domainObject) {
    SculptormetamodelFactory factory = SculptormetamodelFactoryImpl.eINSTANCE;

    Repository repository = factory.createRepository();
    repository.setName(domainObject.getName() + "Repository");

    return domainObject;

How to change auditable column names

The auditable properties are added by a model transformation. You can modify that transformation in this way.

Define your advice in src/main/resources/generator/SpecialCases.ext.

import sculptormetamodel;

around transformation::Transformation::addAuditable(Entity entity) :
         addAuditDateAttribute(entity, "createdDate", "created_date") ->
         addAuditByAttribute(entity, "createdBy", "created_by") ->
         addAuditDateAttribute(entity, "lastUpdated", "updated_date") ->
         addAuditByAttribute(entity, "lastUpdatedBy", "updated_by");

create Attribute addAuditDateAttribute(Entity entity, String propertyName, String databaseName) :
setName(propertyName) ->
setDatabaseColumn(databaseName) ->
setType("java.util.Date") ->
setNullable(true) ->

create Attribute addAuditByAttribute(Entity entity, String propertyName, String databaseName) :
setName(propertyName) ->
setDatabaseColumn(databaseName) ->
setType("String") ->
setLength("50") ->
setNullable(true) ->

How to change syntactic sugar

It is rather easy to change the concrete syntax of the DSL. It is defined in the XText grammar sculptordsl.xtext.

For example, as an alternative to ! we would like to be able to use not.

Define a rule.

terminal NOT :

Use this rule instead of the “!” literal.

((notChangeable?=NOT "changeable") | ("changeable")) |

If you change the core elements of the language, such as DslService, DslEntity, DslAttribute, you have to change the transformation also, which is located in DslTransformation.xpt in the ´sculptor-generator-core`` project.

Try DSL changes

When working with the DSL you generate the parser and editor by running the GenerateSculptordsl.mwe in the org.sculptor.dsl project (Run as MWE Workflow). Thereafter you can try the DSL editor by launching a runtime workbench as an Eclipse application, which includes the plugins in the workspace automatically.

How to add a new feature in the meta model

We need to be able to define an additional feature for the attributes of the Domain Objects. It should be possible to define that an attribute is included in the constructor, but still have setter method. A complement to the changeable feature. Let us call this new feature required.

  1. Open the sculptormetamodel.ecore_diagram with the graphical editor. Add a new EAttribute to the Attribute “class”. Set the name to required in the Properties view. Select EBoolean in the EAttribute Type.

Required Attribute
Figure 4. Screenshot of metamodel for required attribute

  1. Open the sculptormetamodel.genmodel and right click on the top node. Select Generate Model.

  2. Open sculptordsl.xtext and add required in the same way as nullable in the DslAttribute section. Note that required should by default be treated as false when not specified.

  3. Run GenerateSculptordsl.mwe in org.sculptor.dsl project. This can be done by right clicking GenerateSculptordsl.mwe and selecting “Run as MWE Workflow”.

  4. Open DslTransformation.ext and add the “copy” of the required property in the same way as the nullable property in the create Attribute method.

    setRequired(attribute.required) ->
  5. Modify the code generation templates. In this case it was only needed to adjust the logic for the constructorAttributes method, which is located in helper.ext.

  6. Build with mvn clean install.

  7. Install the DSL editor plugins and test the new feature with the reference application.

How to Add a New Core Concept

This section describes all steps of how to add a completely new concept, Consumer in this case. Consumer is implemented in Sculptor and since this description is very brief you have to look at the details in the source code to make any sense out of this.

  1. Start with the Ecore meta model. Open the sculptormetamodel.ecore_diagram with the graphical editor.

    • Add Consumer class.
    • Add generalization link from Consumer to NamedElement, a Consumer has a name.
    • Add bi-directional aggregate association between Module and Consumer, one Module can contain many Consumers, a Consumer belongs to one Module.
    • Add association from Consumer to Service, serviceDependencies, used for dependency injection of Services into the Consumer.
    • Add association from Consumer to Repository, repositoryDependencies, used for dependency injection of Repositories into the Consumer.

    Consumer Meta Model
    Figure 5. Screenshot of metamodel for consumer

  2. DSL grammar, located in sculptordsl.xtext

    • Define DslConsumer

      DslConsumer :
            "Consumer" name=ID "{"
              ("unmarshall" "to" (("@")?messageRoot=ID))?
              ("queueName" "=" queue=DslQueueIdentifier )?
    • Add (consumers+=DslConsumer)* to DslModule
    • Add DslDependency in the same way as the existing DslRepositoryDependency
    • Run GenerateSculptordsl.mwe2 in org.sculptor.dsl to generate DSL meta model and DSL editor
  3. DSL constraints checks, located in and SculptordslChecks.chk.

    • Add DslServiceDependency in the same way as the existing DslRepositoryDependency, findService is already implemented in sculptordsl.ext
  4. Transformation of DSL model to Ecore meta model, located in DslTransformation.ext in sculptor-generator-core.

    • Add consumers.addAll(module.consumers.transform()) -> to the Module transformation.
    • Add create sculptormetamodel::Consumer this transform(DslConsumer consumer)...
    • Add module.consumers.transformDependencies() -> to the Module transformation.
    • Add transformDependencies(DslConsumer consumer)...
    • Add sculptormetamodel::Service transformServiceDependency(DslDependency dependency)...
  5. Meta model constraints, located in constraints.chk in sculptor-generator-core.

    • Add context Consumer ERROR "Not allowed to delegate to repository...
    • Add check of cyclic dependencies in DependencyConstraints class
  6. Code generation template

    • Add Consumer.xpt and everything to generate for the Consumers.
    • Add properties for package and framework classes. This is done in, properties.ext and helper.ext.
    • Add EXPAND Consumer in Root.xpt, you need allConsumers() in helper.ext, which can be implemented in the same way as allServices.
    • Add Spring stuff for the Consumers in Spring.xpt.

How to define a Sculptor cartridge

Cartridges in Sculptor provide a means to package extensions to Sculptor that projects may enable or disable via the cartridges property. Some features within Sculptor itself are packaged as cartridges, for example the builders feature and MongoDB support.

To define a cartridge:

Fork me on GitHub