Create a Client Project

Creation of a new Eclipse project has been discussed in some details here, so we will omit the screenshots for the common parts.

  • In Eclipse go to "File > New > Project". Select a "Java Project" for the project type and click "Next".
  • Enter "cayenne-tutorial-client" for the project name, select "Create separate source and output folders" radio button and click "Next".
  • On the next ("Java Settings") screen go to the "Libraries" tab and click "Add External Jar" button on the right to add the following .jar files needed by the client:
    • cayenne-client-nodeps.jar, located in the "lib" directory of the Cayenne installation.
    • hessian.jar, version 3.0.13, that can be downloaded from here.
    • commons-logging.jar, version 1.0.4 or newer, that can be downloaded from here.
    • commons-lang.jar, version 2.1 or newer, that can be downloaded from here.
    • commons-collections.jar, version 3.1 or newer, that can be downloaded from here:

  • When done click "Finish" and the new project should appear in Eclipse.

Client Class Generation

Client classes are a lightweight version of server-side DataObjects. They are generated using a separate template. Let's lace them in a new client project.

  • Start CayenneModeler and open "cayenne-tutorial/src/cayenne.xml" file (note that the mapping files stay in the server project; client will obtain mapping information from the server).
  • Select an "UntitledDomainMap" DataMap and check "Allow Client Entities"
  • Enter "cayenne.tutorial.client" for the "Client Java Package" and click an "Update.." button next to it to refresh the client package of all entities.

  • Now select "Tools > Generate Classes" menu.
  • For "Type" select "Client Persistent Objects" (this will use a different generation template).
  • For the output directory select "cayenne-tutorial-client/src" directory of your client Eclipse project.
  • Click "Generate".

Now go back to Eclipse, right click on "cayenne-tutorial-client" project and select "Refresh" - you should see a pair of classes generated for each mapped entity. Note that you should not modify the classes whose names start with "_" (underscore), as they will be replaced on subsequent generator runs. Instead all custom logic should be placed in their subclasses located in "cayenne.tutorial" package - those will never be overwritten by the class generator.

Next Step: Remote Object Persistence Tutorial WebService