doc'd default and insert on version
revised section on ddl-related mapping elements git-svn-id: https://svn.jboss.org/repos/hibernate/trunk/Hibernate3/doc@7899 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
337051f1a2
commit
6de029bf3d
|
@ -1057,7 +1057,7 @@
|
||||||
|
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="mapping-declaration-version" revision="2">
|
<sect2 id="mapping-declaration-version" revision="3">
|
||||||
<title>version (optional)</title>
|
<title>version (optional)</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -1074,6 +1074,7 @@
|
||||||
<area id="version4" coords="5 70"/>
|
<area id="version4" coords="5 70"/>
|
||||||
<area id="version5" coords="6 70"/>
|
<area id="version5" coords="6 70"/>
|
||||||
<area id="version6" coords="7 70"/>
|
<area id="version6" coords="7 70"/>
|
||||||
|
<area id="version7" coords="8 70"/>
|
||||||
</areaspec>
|
</areaspec>
|
||||||
<programlisting><![CDATA[<version
|
<programlisting><![CDATA[<version
|
||||||
column="version_column"
|
column="version_column"
|
||||||
|
@ -1082,6 +1083,7 @@
|
||||||
access="field|property|ClassName"
|
access="field|property|ClassName"
|
||||||
unsaved-value="null|negative|undefined"
|
unsaved-value="null|negative|undefined"
|
||||||
generated="true|false"
|
generated="true|false"
|
||||||
|
insert="true|false"
|
||||||
node="element-name|@attribute-name|element/@attribute|."
|
node="element-name|@attribute-name|element/@attribute|."
|
||||||
/>]]></programlisting>
|
/>]]></programlisting>
|
||||||
<calloutlist>
|
<calloutlist>
|
||||||
|
@ -1124,6 +1126,14 @@
|
||||||
See the discussion of <xref linkend="mapping-generated">generated properties</xref>.
|
See the discussion of <xref linkend="mapping-generated">generated properties</xref>.
|
||||||
</para>
|
</para>
|
||||||
</callout>
|
</callout>
|
||||||
|
<callout arearefs="version7">
|
||||||
|
<para>
|
||||||
|
<literal>insert</literal> (optional - defaults to <literal>true</literal>):
|
||||||
|
Specifies whether the version column should be included in SQL insert statements.
|
||||||
|
May be set to <literal>false</literal> if and only if the database column
|
||||||
|
is defined with a default value of <literal>0</literal>.
|
||||||
|
</para>
|
||||||
|
</callout>
|
||||||
</calloutlist>
|
</calloutlist>
|
||||||
</programlistingco>
|
</programlistingco>
|
||||||
|
|
||||||
|
@ -2532,7 +2542,7 @@
|
||||||
|
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="mapping-column" revision="3">
|
<sect2 id="mapping-column" revision="4">
|
||||||
<title>column and formula elements</title>
|
<title>column and formula elements</title>
|
||||||
<para>
|
<para>
|
||||||
Any mapping element which accepts a <literal>column</literal> attribute will alternatively
|
Any mapping element which accepts a <literal>column</literal> attribute will alternatively
|
||||||
|
@ -2550,7 +2560,8 @@
|
||||||
unique-key="multicolumn_unique_key_name"
|
unique-key="multicolumn_unique_key_name"
|
||||||
index="index_name"
|
index="index_name"
|
||||||
sql-type="sql_type_name"
|
sql-type="sql_type_name"
|
||||||
check="SQL expression"/>]]></programlisting>
|
check="SQL expression"
|
||||||
|
default="SQL expression"/>]]></programlisting>
|
||||||
|
|
||||||
<programlisting><![CDATA[<formula>SQL expression</formula>]]></programlisting>
|
<programlisting><![CDATA[<formula>SQL expression</formula>]]></programlisting>
|
||||||
|
|
||||||
|
|
|
@ -68,58 +68,89 @@
|
||||||
First, customize your mapping files to improve the generated schema.
|
First, customize your mapping files to improve the generated schema.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<sect2 id="toolsetguide-s1-2" revision="1">
|
<sect2 id="toolsetguide-s1-2" revision="3">
|
||||||
<title>Customizing the schema</title>
|
<title>Customizing the schema</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Many Hibernate mapping elements define an optional attribute named <literal>length</literal>. You may set
|
Many Hibernate mapping elements define optional attributes named <literal>length</literal>,
|
||||||
the length of a column with this attribute. (Or, for numeric/decimal data types, the precision.)
|
<literal>precision</literal> and <literal>scale</literal>. You may set the length, precision
|
||||||
|
and scale of a column with this attribute.
|
||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<programlisting><![CDATA[<property name="zip" length="5"/>]]></programlisting>
|
||||||
Some tags also accept a <literal>not-null</literal> attribute (for generating a <literal>NOT NULL</literal>
|
<programlisting><![CDATA[<property name="balance" precision="12" scale="2"/>]]></programlisting>
|
||||||
constraint on table columns) and a <literal>unique</literal> attribute (for generating <literal>UNIQUE</literal>
|
|
||||||
constraint on table columns).
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Some tags accept an <literal>index</literal> attribute for specifying the
|
Some tags also accept a <literal>not-null</literal> attribute (for generating a
|
||||||
name of an index for that column. A <literal>unique-key</literal> attribute
|
<literal>NOT NULL</literal> constraint on table columns) and a <literal>unique</literal>
|
||||||
can be used to group columns in a single unit key constraint. Currently, the
|
attribute (for generating <literal>UNIQUE</literal> constraint on table columns).
|
||||||
specified value of the <literal>unique-key</literal> attribute is
|
</para>
|
||||||
<emphasis>not</emphasis> used to name the constraint, only to group the
|
|
||||||
columns in the mapping file.
|
<programlisting><![CDATA[<many-to-one name="bar" column="barId" not-null="true"/>]]></programlisting>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<element column="serialNumber" type="long" not-null="true" unique="true"/>]]></programlisting>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
A <literal>unique-key</literal> attribute may be used to group columns in
|
||||||
|
a single unique key constraint. Currently, the specified value of the
|
||||||
|
<literal>unique-key</literal> attribute is <emphasis>not</emphasis> used
|
||||||
|
to name the constraint in the generated DDL, only to group the columns in
|
||||||
|
the mapping file.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<programlisting><![CDATA[<many-to-one name="org" column="orgId" unique-key="OrgEmployeeId"/>
|
||||||
Examples:
|
<property name="employeeId" unique-key="OrgEmployee"/>]]></programlisting>
|
||||||
</para>
|
|
||||||
|
|
||||||
<programlisting><![CDATA[<property name="foo" type="string" length="64" not-null="true"/>
|
|
||||||
|
|
||||||
<many-to-one name="bar" foreign-key="fk_foo_bar" not-null="true"/>
|
|
||||||
|
|
||||||
<element column="serial_number" type="long" not-null="true" unique="true"/>]]></programlisting>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Alternatively, these elements also accept a child <literal><column></literal> element. This is
|
An <literal>index</literal> attribute specifies the name of an index that
|
||||||
particularly useful for multi-column types:
|
will be created using the mapped column or columns. Multiple columns may be
|
||||||
|
grouped into the same index, simply by specifying the same index name.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<programlisting><![CDATA[<property name="foo" type="string">
|
<programlisting><![CDATA[<property name="lastName" index="CustName"/>
|
||||||
<column name="foo" length="64" not-null="true" sql-type="text"/>
|
<property name="firstName" index="CustName"/>]]></programlisting>
|
||||||
</property>]]></programlisting>
|
|
||||||
|
|
||||||
<programlisting><![CDATA[<property name="bar" type="my.customtypes.MultiColumnType"/>
|
<para>
|
||||||
<column name="fee" not-null="true" index="bar_idx"/>
|
A <literal>foreign-key</literal> attribute may be used to override the name
|
||||||
<column name="fi" not-null="true" index="bar_idx"/>
|
of any generated foreign key constraint.
|
||||||
<column name="fo" not-null="true" index="bar_idx"/>
|
</para>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<many-to-one name="bar" column="barId" foreign-key="FKFooBar"/>]]></programlisting>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
Many mapping elements also accept a child <literal><column></literal> element.
|
||||||
|
This is particularly useful for mapping multi-column types:
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<property name="name" type="my.customtypes.Name"/>
|
||||||
|
<column name="last" not-null="true" index="bar_idx" length="30"/>
|
||||||
|
<column name="first" not-null="true" index="bar_idx" length="20"/>
|
||||||
|
<column name="initial"/>
|
||||||
</property>]]></programlisting>
|
</property>]]></programlisting>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The <literal>sql-type</literal> attribute allows the user to override the default mapping
|
The <literal>default</literal> attribute lets you specify a default value for
|
||||||
of Hibernate type to SQL datatype.
|
a column (you should assign the same value to the mapped property before
|
||||||
|
saving a new instance of the mapped class).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<property name="credits" type="integer" insert="false">
|
||||||
|
<column name="credits" default="10"/>
|
||||||
|
</property>]]></programlisting>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<version name="version" type="integer" insert="false">
|
||||||
|
<column name="version" default="0"/>
|
||||||
|
</property>]]></programlisting>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The <literal>sql-type</literal> attribute allows the user to override the default
|
||||||
|
mapping of a Hibernate type to SQL datatype.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<property name="balance" type="float">
|
||||||
|
<column name="balance" sql-type="decimal(13,3)"/>
|
||||||
|
</property>]]></programlisting>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The <literal>check</literal> attribute allows you to specify a check constraint.
|
The <literal>check</literal> attribute allows you to specify a check constraint.
|
||||||
|
@ -152,7 +183,17 @@
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>length</literal></entry>
|
<entry><literal>length</literal></entry>
|
||||||
<entry>number</entry>
|
<entry>number</entry>
|
||||||
<entry>column length/decimal precision</entry>
|
<entry>column length</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><literal>precision</literal></entry>
|
||||||
|
<entry>number</entry>
|
||||||
|
<entry>column decimal precision</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><literal>scale</literal></entry>
|
||||||
|
<entry>number</entry>
|
||||||
|
<entry>column decimal scale</entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>not-null</literal></entry>
|
<entry><literal>not-null</literal></entry>
|
||||||
|
@ -179,20 +220,28 @@
|
||||||
<entry><literal>foreign_key_name</literal></entry>
|
<entry><literal>foreign_key_name</literal></entry>
|
||||||
<entry>
|
<entry>
|
||||||
specifies the name of the foreign key constraint generated
|
specifies the name of the foreign key constraint generated
|
||||||
for an association, use it on <one-to-one>, <many-to-one>,
|
for an association, for a <literal><one-to-one></literal>,
|
||||||
<key>, and <many-to-many> mapping elements. Note that
|
<literal><many-to-one></literal>, <literal><key></literal>,
|
||||||
|
or <literal><many-to-many></literal> mapping element. Note that
|
||||||
<literal>inverse="true"</literal> sides will not be considered
|
<literal>inverse="true"</literal> sides will not be considered
|
||||||
by <literal>SchemaExport</literal>.
|
by <literal>SchemaExport</literal>.
|
||||||
</entry>
|
</entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>sql-type</literal></entry>
|
<entry><literal>sql-type</literal></entry>
|
||||||
<entry><literal>column_type</literal></entry>
|
<entry><literal>SQL column type</literal></entry>
|
||||||
<entry>
|
<entry>
|
||||||
overrides the default column type (attribute of
|
overrides the default column type (attribute of
|
||||||
<literal><column></literal> element only)
|
<literal><column></literal> element only)
|
||||||
</entry>
|
</entry>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><literal>default</literal></entry>
|
||||||
|
<entry>SQL expression</entry>
|
||||||
|
<entry>
|
||||||
|
specify a default value for the column
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>check</literal></entry>
|
<entry><literal>check</literal></entry>
|
||||||
<entry>SQL expression</entry>
|
<entry>SQL expression</entry>
|
||||||
|
@ -205,7 +254,7 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The <literal><comment></literal> element allows you to specify a comments
|
The <literal><comment></literal> element allows you to specify comments
|
||||||
for the generated schema.
|
for the generated schema.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
@ -275,7 +324,7 @@
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
||||||
<entry>select a <tt>NamingStrategy</tt></entry>
|
<entry>select a <literal>NamingStrategy</literal></entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>--config=hibernate.cfg.xml</literal></entry>
|
<entry><literal>--config=hibernate.cfg.xml</literal></entry>
|
||||||
|
@ -430,7 +479,7 @@ new SchemaExport(cfg).create(false, true);]]></programlisting>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
||||||
<entry>select a <tt>NamingStrategy</tt></entry>
|
<entry>select a <literal>NamingStrategy</literal></entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>--properties=hibernate.properties</literal></entry>
|
<entry><literal>--properties=hibernate.properties</literal></entry>
|
||||||
|
@ -476,7 +525,7 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
|
||||||
|
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="toolsetguide-s1-7" revision="1">
|
<sect2 id="toolsetguide-s1-8" revision="1">
|
||||||
<title>Schema validation</title>
|
<title>Schema validation</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -504,7 +553,7 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
|
||||||
<tbody>
|
<tbody>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
||||||
<entry>select a <tt>NamingStrategy</tt></entry>
|
<entry>select a <literal>NamingStrategy</literal></entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><literal>--properties=hibernate.properties</literal></entry>
|
<entry><literal>--properties=hibernate.properties</literal></entry>
|
||||||
|
@ -527,7 +576,7 @@ new SchemaValidator(cfg).validate();]]></programlisting>
|
||||||
|
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="toolsetguide-s1-7">
|
<sect2 id="toolsetguide-s1-9">
|
||||||
<title>Using Ant for schema validation</title>
|
<title>Using Ant for schema validation</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
|
Loading…
Reference in New Issue