2007-05-17

SimpleTapestry 5 CRUD application -Step 03, "user" bean creation.

A small lyrical digression: I'd like to follow the MVC pattern in creating the application and it's time now to add some "model" or "bean" code into the project.

After the Step 02 we already have a login page and a service for user authentication, but we still have no «user», so :
  1. Create a new class, package = org.example.TSA504.beans, name=TUser, implements Serializable, and generate the serialVersionUID field.

  2. Now, I'd like to use Hibernate with annotations and avoid boring .hbm files writing/generating, so we need to add some libraries into the project. Create a new folder TSA504\lib\ , find and copy ejb3-persistence.jar and hibernate-annotations.jar into it ( I found the files in hibernate-entitymanager-3.3.1.GA\lib\).

  3. After that, add the libraries into the project's Java Build Path:

  4. Let's start to «create» our user bean:

@Entity
@Table(name = "TUSER")
public class TUser implements Serializable {
private static final long serialVersionUID = 7769115993193444629L;
protected long id;
protected String userName;
protected String firstName;
protected String MI;
protected String lastName;
protected String email;
protected String password;
...
}

So, as you see, it's quite a simple class, you can find the listing here. Pay attention to the imports.

  1. The bean implements the Serializable interface, so we have to write equals(), hashCode() and toString() methods. Have to say honestly, I've been impressed by Appfuse project, so I've picked up a bit from there. Note, toString() realization needs commons-lang-2.3.jar, so don't forget to add the library to the project.


    6. SimpleTapestry 5 CRUD application -Step 06, tweaking a grid a bit.
    5. Simple Tapestry 5 CRUD application - BeanEditForm and Grid screencasts aprobation.
    4. SimpleTapestry 5 CRUD application -Step 04 Adding some basic Hibernate features into the project.
    3. SimpleTapestry 5 CRUD application -Step 03, "user" bean creation.
    2. SimpleTapestry 5 CRUD application -Step 02, adding a service.
    1. SimpleTapestry 5 CRUD application -Step 01.

2 comments:

R. Sanders said...

I don't know about other IDEs (I assume they have something similar), but Eclipse has a pretty nice tool under the "Source" menu for "Generate equals() and hashCode()" that does what the name suggests.

Лозован Евгений said...

Yes, Robert, you are right, thank for pointing, I was too lazy to find that by myself :(.