Sequence diagrams are a great way to design how objects should collaborate. HiberObjects supports the use of sequence diagrams for design sketches. The sketches can then be refined and used to generate code for class and operation skeletons.
This following example shows how to use this to design login functionality for a GWT application.
Right-click on a package in the Project Explorer view and select New Sequence Diagram.
Draw an actor, objects and messages:

Now, we can create a class for each object and set stereotypes for the classes:


The yellow color indicates that the objects are connected to designed classes.
Right-click on a message to create a corresponding operation in the target class. (This is only possible if the target object is an instance of a designed class.)
The message will then turn yellow, to indicate that it is connected to a designed operation. The operation name and parameters will then be updated if you edit the message text.
You can define parameters by typing a message with a format like
message(x=3) etc.
HiberObjects will then guess the parameter type based on the value
and create an operation void message(int x) etc.
In our example, we will create the following messages and parameters:

We need to define attributes in the User class
and create a query to find a user by name.
This can be done in a class diagram:

The New > Query command creates an operation
User[*] findByUserName(String username) in class UserDAO.
The * means that the method will return a List of
User objects. But we only want to return 0 or 1 User.
Edit the operation as follows:

This will generate the following code:
public User findByUsername(String username) {
Query query = getSession().createQuery("from User u where u.username = :username");
query.setParameter("username", username);
java.util.List list = query.getResultList();
if (list.size() == 1) {
return (User) list.get(0);
} else {
return null;
}
}Now we can go back to the sequence diagram and connect the message to the new operation:

When the diagram is saved, Java code will be generated. In our example, this will generate code for a screen, a GWT Service, a DAO and a Persistent class.
There is no specific code generation for screens (yet), but the other stereotypes generate a lot of useful code.
The stereotype <<GWT Service>> will generate a GWT servlet and the 2 interfaces that are necessary:
The stereotype <<DAO>> will generate code for sessions, queries etc:
Stereotype <<Persistent>> will generate the following code: