Entities are defined in XML format.
An entity is represented by the tag <entity> . Each tag represents a class that will be generated by the code generator.
Xml file can contain one or more entities. He should be well distributed entities xml file for readability.
The header of an XML file containing entities should have the following schematic:
<?xml version="1.0" encoding="UTF-8"?>
<domain-models xmlns="http://apps.axelor.com/xml/ns/domain-models"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://apps.axelor.com/xml/ns/domain-models http://apps.axelor.com/xml/ns/domain-models/domain-models_0.9.xsd">
...
</domain-models>
domain-models_0.9.xsd being the XSD to validate the structure and content type of the file.
The version of the XSD should be used in conjunction with the release of the source. Here is the version 0.9.
Each XML file must contain a module embodied by the tag <Module> . Each entity defined in a file up to the package defined in the <module>.
<?xml version="1.0" encoding="UTF-8"?>
<domain-models xmlns="http://apps.axelor.com/xml/ns/domain-models"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://apps.axelor.com/xml/ns/domain-models http://apps.axelor.com/xml/ns/domain-models/domain-models_0.9.xsd">
<module name="contact" package="com.axelor.contact.db"/>
<entity ... >
....
</entity>
<entity ... >
....
</entity>
</domain-models>
Entities can be documented by the xml section CDATA . This documentation will be carried directly into the generated class as javadoc.
<entity name="Title">
<![CDATA[
This class represents the name initial like Mr., Mrs. etc.
For example:
Title title = new Title();
title.setCode("mr");
title.setName("Mr.");
contact.setTitle(title);
@author John Smith <[email protected]>
@since 1.0
]]>
<string name="code" column="ccc" required="true" unique="true" min="2" help="The unique code."/>
<string name="name" required="true" unique="true" min="2" help="The title name."/>
</entity>
An entity has a number of attributes which are listed below and their definitions:
Attribute | Definition | Default | Possible values |
---|---|---|---|
lang | Specifies in which language generate the class. | Java | java , groovy |
name | Name of entity (must be capitalized). | None. This attribute is required. | string |
table | Specifies the name of the table to use. | None. The name of the table is managed by the code generator. | string |
indexes | Specifies multiple indexes. indexes = "name, code" indexes = "name, code, name, customer" |
No | string |
cacheable | Specifies whether the entity should be cached if the cache is enabled. | false | true , false |
hashAll | Specifies whether to use all the "simple" fields (fields except functions) as a key hash (Generation of the method equals and hashCode ). Some fields may be ignored by spécificiant hashKey = "false". |
false | true , false |
logUpdates | Specifies whether the log changes to the records of that entity must be enabled. | true | true , false |
sequential | Specifies the use of a generic or entity-specific sequence. | true | true , false |
By default, if the attribute table is missing, the table name for an entity will be in this format:
moduleName.toUpperCase() + "_" + CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, entityName)
Object definition Circle in XML:
<module name="contact" package="com.axelor.contact.db"/>
<entity name="Circle" cachable="true">
<string name="code" required="true" unique="true" min="2"/>
<string name="name" required="true" unique="true" min="2"/>
</entity>
JAVA code generated:
package com.axelor.contact.db;
import javax.persistence.Cacheable;
...
@Entity
@Cacheable
@Table(name = "CONTACT_CIRCLE")
public class Circle extends AuditableModel {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CONTACT_CIRCLE_SEQ")
@SequenceGenerator(name = "CONTACT_CIRCLE_SEQ", sequenceName = "CONTACT_CIRCLE_SEQ", allocationSize = 1)
private Long id;
@NotNull
@Size(min = 2)
@Index(name = "CONTACT_CIRCLE_CODE_IDX")
@Column(unique = true)
private String code;
@NotNull
@Size(min = 2)
@Index(name = "CONTACT_CIRCLE_NAME_IDX")
@Column(unique = true)
private String name;
public Circle() {
}
public Circle(String code, String name) {
this.code = code;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
...
}