blob: 496d401b5ea7d35284f45a666a1318c7e3029c03 [file] [log] [blame]
Title: Generate Primary Key Support
<H3><A name="GeneratePrimaryKeySupport-GeneratePrimaryKeySupport"></A>Generate Primary Key Support</H3>
<P>One of Cayenne core features is automatic generation of the database primary keys for the new objects. This requires a set of special database objects to be present in the database. Those are adapter-specific and can be special lookup tables, stored procedures, sequences, etc. If the database schema was generated by CayenneModeler as described in previous chapters, chances are that all needed database objects were already created. Otherwise, if there was an existing schema, these objects must be created in the database. The easiest way to do that is to use CayenneModeler &quot;<TT>Tools &gt; Generate Database Schema</TT>&quot; menu item, setting special generation options.</P>
<P><B>Create Primary Key Support.</B> Select a DataMap and choose &quot;<TT>Tools -&gt; Generate Database Schema</TT>&quot; from the menu, &quot;Connect to Database&quot; dialog appears.</P>
<P><SPAN class="image-wrap" style=""><IMG src="generate-primary-key-support.data/generate-connect.jpg" style="border: 0px solid black"></SPAN></P>
<P><B>Configure Database Connection.</B> &quot;Connect to Database&quot; dialog allows to specify alternative connection parameters. If a DataMap has a DataNode, then this DataNode connection information is shown by default. You can use suggested default connection, select one of the stored local DataSources from &quot;Saved DataSources&quot; dropdown (those can be edited on the spot by clicking &quot;...&quot; button), or type your own info. When desired connection is selected, click &quot;Continue&quot;. Cayenne will attempt to connect to the database and if connection is successful, &quot;Options&quot; dialog is presented.</P>
<P><SPAN class="image-wrap" style=""><IMG src="generate-primary-key-support.data/generate-options-pk.jpg" style="border: 0px solid black"></SPAN></P>
<P>You must uncheck all options except for &quot;Create Primary key Support&quot;, and then click &quot;Generate&quot;. If there were any database specific errors during generation they will be listed in a status window. Sometimes such errors can be simply ignored (e.g. when a there was an existing primary key support already configured in the DB).</P>