- In Eclipse create a new class called "Main" in the "cayenne.tutorial" package.
- Create a standard "main" method to make it a runnable class:
- The first thing you need to be able to access the database is a DataContext instance. In this simple case of a standalone command line application, it can be obtained by calling a static method:
DataContext is a single session a user needs to work with Cayenne. DataContext has methods to execute queries and manage persistent objects. We'll discuss them in the following chapters. When the first DataContext is created in the application, Cayenne loads XML mapping files and creates an access stack that can later be reused for other DataContexts.
Let's check what happens when you run the application. First you need to close CayenneModeler (as Derby does not allow multiple applications accessing the same database in the embedded mode). After that right click the "Main" class in Eclipse and select "Run As > Java Application". In the console you'll see output similar to this, indicating that Cayenne stack has been started:
The log omits most stack loading details. You can configure a more detailed output by following the instructions in the logging chapter.
Next Step: Tutorial DataObjects