Declaring Entities
Entities are related to tables in the SQL world and to classes in the java world.
Entities are declared one after the other. The order of the declaration has no impact on the application generation. Entities are described by a unique name and by a set of attributes of elementary types. Attributes that are part of a relationship to another entity are declared separately. Additional information can be provided using DOM tags or annotations.
Valid elementary types for attributes are:
-
String, to represent any string value. -
Instant, to represent an instant in time. -
LocalDate, to represent a date without a time zone. -
LocalTime, to represent a local time. -
LocalDateTime, to represent a date with time without a time zone. -
Duration, to represent a duration (time between two dates). -
Integer, to represent an integer value. -
Long, to represent a long value. -
Double, to represent a double value. -
Boolean, to represent a boolean value. -
Binary, to represent binary data.
More information on the data types can be found in Section Understanding Data Types
The following sample code declares an entity named Resource which has two attributes:
-
an
idof typeString -
a
nameof typeString
The DOM tag states that the id attribute is part of the Resource primary key.
entity Resource {
// DOM [primary.keys] : [id]
id String required,
name String
}
Note that, if Resource was also part of the primary key, then id would have to be replaced by [id, name].