5.3. Model Java Classes

A java class may map a database table it self or may be a part of a table per class hierarchy.

Class identifier

To specify the primary key of your class you need to add a field named 'id' or '<entity>Id' where <entity> is the name of the class with the first letter in lower case. Ex:
public class Editor {

	private int editorId; 
	
	public int getEditorId() {
		return editorId;
	}

	public void setEditorId(int editorId) {
		this.editorId = editorId;
	}
}
			
When application will be started, hibernate will synchronize the mappings generated and loaded by wedge with the database schema and the table mapped by java class Editor will look like this:
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| editor_id | int(11)      | NO   | PRI |         | auto_increment |
+-----------+--------------+------+-----+---------+----------------+
			

Class properties

Class properties are simple class fields that have some types that are not declared as model components in the configuration file. Thus, a class property does not need more than specifing the field in the java class. Let's extend our example with some few properties.
public class Editor {
	
	private int editorId;
	
	private String name;
	
	public int getEditorId() {
		return editorId;
	}

	public void setEditorId(int editorId) {
		this.editorId = editorId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
After we have added the 'name' property our generated table will look like this:
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| editor_id | int(11)      | NO   | PRI |         | auto_increment |
| name      | varchar(255) | YES  |     |         |                |
+-----------+--------------+------+-----+---------+----------------+
But now there is a problem. How can we specify that this field is not nullable? The fact is that we need to provide a way to make the propery not nullabe without no configuration of any kind.

The solution that wedge come with is to put information in the modifiers of the property fields. Specifing a field as being 'protected' and not 'private' as usual gives the signal that it should be not nullable. It may seem strange to you... Well we'll see about it! Time will prove if it is a good methodology. :-)

After making the name field 'protected' will end up with the follwing table:

+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| editor_id | int(11)      | NO   | PRI |         | auto_increment |
| name      | varchar(255) | NO   |     |         |                |
+-----------+--------------+------+-----+---------+----------------+