Attribute Default Value
In the Entity Relationship Diagram, user can specify the default value for each column. The database set default value to the column when a subsequent INSERT statement omits the value for the column.
Column Default Value
Before create any entity in Entity Relationship Diagram (ERD), you may configure the MySQL database as default database.
Select
Tools >
Object-Relational Mapping (ORM) >
Database Configuration... on the menu.
Select
MySQL and enter the database information includes
Connection URL,
User, etc… and then click
OK.
Setting Column Default Value
Create an Entity Relationship Diagram (ERD) and add an Entity called
student in the ERD. The student entity contains the following columns with default value and constraint:
| Column | Type | Default Value | Constraint |
| id | int | | Primary Key |
| name | varchar(255) | none | |
| age | int | 18 | |
| gender | varchar(1) | m | |


Reversing Column Default Value
You can reverse the table with default value from database. You will use the following SQL statement to create the staff table in MySQL database.
Execute the “create table”
SQL statement on MySQL database.
CREATE TABLE staff(id int, name varchar(25), mobile varchar(15), drivers_licence varchar(20) DEFAULT 'No',
PRIMARY KEY(id))type=InnoDB;

the staff table only the drivers_licence column has default value ‘No’.
Open new project in DBVA. Select
Tools >
Object-Relational Mapping (ORM) >
Reverse Database… on the menu.
Select
Java language and click
Next>.
Configure the MySQL database and click
Next>.
Select the staff table and click Finish to reverse.
Check the default value in
drivers_licence column is reversed from the database.
Synchronizing Default Value
The DBVA can help user to reverse the default value from database to the ERD column. The default value on the column also can synchronize to be an initial value for the corresponding attribute in Class Diagram.
Reopen the project create on the
Setting Column Default Value section(contain student entity).
Select
Tools >
Object-Relational Mapping (ORM) >
Synchronize to Class Diagram on menu.
The Class Diagram is created and contains the class call
Student. Each attributes have initial value. The initial value will be assign for the attribute in generate source code.
When you modify the default value on the ERD, you can synchronize to Class Diagram again then the initial value will follow the default value to modify but you have modified the initial value and synchronize from ERD to Class Diagram, DBVA detect the conflict between the initial value and default value and show the Change initial value dialog to request user make decision to update the initial value or not.
Generating Code and DDL
The default database is configured at the beginning of the document. After Synchronize to Class Diagram, you can generate the persistable code and DDL file.
Select
Tools >
Object-Relational Mapping (ORM) >
Generate Code… on the menu.
Select
Code and Database for
Generate option and
Java for
Language option. Select the
output path for the generate persistable Java code and DDL file.
Click
Database tab, select
Create Database for
Generate Database option and select
Export to database and
Generate DDL options. Finally, click
OK button to start generate Java code and DDL file to output path.
From attributedefault.ddl file. All the default value is created for column in the create table statement.
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT 'none',
`age` int DEFAULT 18, `gender` varchar(1) DEFAULT 'm', PRIMARY KEY (`id`)) type=InnoDB;
From generated Student Class. You can observer that the initial value is set for corresponding attribute.
public class Student {
...
private int id;
private String name = "none";
private Integer age = new Integer(18);
private String gender = "m";
...
}
Downloads
Resources