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 id="mapping-declaration-version" revision="2">
|
||||
<sect2 id="mapping-declaration-version" revision="3">
|
||||
<title>version (optional)</title>
|
||||
|
||||
<para>
|
||||
|
@ -1074,6 +1074,7 @@
|
|||
<area id="version4" coords="5 70"/>
|
||||
<area id="version5" coords="6 70"/>
|
||||
<area id="version6" coords="7 70"/>
|
||||
<area id="version7" coords="8 70"/>
|
||||
</areaspec>
|
||||
<programlisting><![CDATA[<version
|
||||
column="version_column"
|
||||
|
@ -1082,6 +1083,7 @@
|
|||
access="field|property|ClassName"
|
||||
unsaved-value="null|negative|undefined"
|
||||
generated="true|false"
|
||||
insert="true|false"
|
||||
node="element-name|@attribute-name|element/@attribute|."
|
||||
/>]]></programlisting>
|
||||
<calloutlist>
|
||||
|
@ -1124,6 +1126,14 @@
|
|||
See the discussion of <xref linkend="mapping-generated">generated properties</xref>.
|
||||
</para>
|
||||
</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>
|
||||
</programlistingco>
|
||||
|
||||
|
@ -2532,7 +2542,7 @@
|
|||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="mapping-column" revision="3">
|
||||
<sect2 id="mapping-column" revision="4">
|
||||
<title>column and formula elements</title>
|
||||
<para>
|
||||
Any mapping element which accepts a <literal>column</literal> attribute will alternatively
|
||||
|
@ -2550,7 +2560,8 @@
|
|||
unique-key="multicolumn_unique_key_name"
|
||||
index="index_name"
|
||||
sql-type="sql_type_name"
|
||||
check="SQL expression"/>]]></programlisting>
|
||||
check="SQL expression"
|
||||
default="SQL expression"/>]]></programlisting>
|
||||
|
||||
<programlisting><![CDATA[<formula>SQL expression</formula>]]></programlisting>
|
||||
|
||||
|
|
|
@ -68,58 +68,89 @@
|
|||
First, customize your mapping files to improve the generated schema.
|
||||
</para>
|
||||
|
||||
<sect2 id="toolsetguide-s1-2" revision="1">
|
||||
<sect2 id="toolsetguide-s1-2" revision="3">
|
||||
<title>Customizing the schema</title>
|
||||
|
||||
<para>
|
||||
Many Hibernate mapping elements define an optional attribute named <literal>length</literal>. You may set
|
||||
the length of a column with this attribute. (Or, for numeric/decimal data types, the precision.)
|
||||
Many Hibernate mapping elements define optional attributes named <literal>length</literal>,
|
||||
<literal>precision</literal> and <literal>scale</literal>. You may set the length, precision
|
||||
and scale of a column with this attribute.
|
||||
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Some tags also accept a <literal>not-null</literal> attribute (for generating a <literal>NOT NULL</literal>
|
||||
constraint on table columns) and a <literal>unique</literal> attribute (for generating <literal>UNIQUE</literal>
|
||||
constraint on table columns).
|
||||
</para>
|
||||
<programlisting><![CDATA[<property name="zip" length="5"/>]]></programlisting>
|
||||
<programlisting><![CDATA[<property name="balance" precision="12" scale="2"/>]]></programlisting>
|
||||
|
||||
<para>
|
||||
Some tags accept an <literal>index</literal> attribute for specifying the
|
||||
name of an index for that column. A <literal>unique-key</literal> attribute
|
||||
can be used to group columns in a single unit key constraint. Currently, the
|
||||
specified value of the <literal>unique-key</literal> attribute is
|
||||
<emphasis>not</emphasis> used to name the constraint, only to group the
|
||||
columns in the mapping file.
|
||||
Some tags also accept a <literal>not-null</literal> attribute (for generating a
|
||||
<literal>NOT NULL</literal> constraint on table columns) and a <literal>unique</literal>
|
||||
attribute (for generating <literal>UNIQUE</literal> constraint on table columns).
|
||||
</para>
|
||||
|
||||
<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>
|
||||
Examples:
|
||||
</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>
|
||||
<programlisting><![CDATA[<many-to-one name="org" column="orgId" unique-key="OrgEmployeeId"/>
|
||||
<property name="employeeId" unique-key="OrgEmployee"/>]]></programlisting>
|
||||
|
||||
<para>
|
||||
Alternatively, these elements also accept a child <literal><column></literal> element. This is
|
||||
particularly useful for multi-column types:
|
||||
An <literal>index</literal> attribute specifies the name of an index that
|
||||
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>
|
||||
|
||||
<programlisting><![CDATA[<property name="foo" type="string">
|
||||
<column name="foo" length="64" not-null="true" sql-type="text"/>
|
||||
</property>]]></programlisting>
|
||||
<programlisting><![CDATA[<property name="lastName" index="CustName"/>
|
||||
<property name="firstName" index="CustName"/>]]></programlisting>
|
||||
|
||||
<programlisting><![CDATA[<property name="bar" type="my.customtypes.MultiColumnType"/>
|
||||
<column name="fee" not-null="true" index="bar_idx"/>
|
||||
<column name="fi" not-null="true" index="bar_idx"/>
|
||||
<column name="fo" not-null="true" index="bar_idx"/>
|
||||
<para>
|
||||
A <literal>foreign-key</literal> attribute may be used to override the name
|
||||
of any generated foreign key constraint.
|
||||
</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>
|
||||
|
||||
<para>
|
||||
The <literal>sql-type</literal> attribute allows the user to override the default mapping
|
||||
of Hibernate type to SQL datatype.
|
||||
The <literal>default</literal> attribute lets you specify a default value for
|
||||
a column (you should assign the same value to the mapped property before
|
||||
saving a new instance of the mapped class).
|
||||
</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>
|
||||
The <literal>check</literal> attribute allows you to specify a check constraint.
|
||||
|
@ -152,7 +183,17 @@
|
|||
<row>
|
||||
<entry><literal>length</literal></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>
|
||||
<entry><literal>not-null</literal></entry>
|
||||
|
@ -179,20 +220,28 @@
|
|||
<entry><literal>foreign_key_name</literal></entry>
|
||||
<entry>
|
||||
specifies the name of the foreign key constraint generated
|
||||
for an association, use it on <one-to-one>, <many-to-one>,
|
||||
<key>, and <many-to-many> mapping elements. Note that
|
||||
for an association, for a <literal><one-to-one></literal>,
|
||||
<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
|
||||
by <literal>SchemaExport</literal>.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>sql-type</literal></entry>
|
||||
<entry><literal>column_type</literal></entry>
|
||||
<entry><literal>SQL column type</literal></entry>
|
||||
<entry>
|
||||
overrides the default column type (attribute of
|
||||
<literal><column></literal> element only)
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>default</literal></entry>
|
||||
<entry>SQL expression</entry>
|
||||
<entry>
|
||||
specify a default value for the column
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>check</literal></entry>
|
||||
<entry>SQL expression</entry>
|
||||
|
@ -205,7 +254,7 @@
|
|||
</table>
|
||||
|
||||
<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.
|
||||
</para>
|
||||
|
||||
|
@ -275,7 +324,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
||||
<entry>select a <tt>NamingStrategy</tt></entry>
|
||||
<entry>select a <literal>NamingStrategy</literal></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>--config=hibernate.cfg.xml</literal></entry>
|
||||
|
@ -430,7 +479,7 @@ new SchemaExport(cfg).create(false, true);]]></programlisting>
|
|||
</row>
|
||||
<row>
|
||||
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
||||
<entry>select a <tt>NamingStrategy</tt></entry>
|
||||
<entry>select a <literal>NamingStrategy</literal></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>--properties=hibernate.properties</literal></entry>
|
||||
|
@ -476,7 +525,7 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
|
|||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="toolsetguide-s1-7" revision="1">
|
||||
<sect2 id="toolsetguide-s1-8" revision="1">
|
||||
<title>Schema validation</title>
|
||||
|
||||
<para>
|
||||
|
@ -504,7 +553,7 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
|
|||
<tbody>
|
||||
<row>
|
||||
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
|
||||
<entry>select a <tt>NamingStrategy</tt></entry>
|
||||
<entry>select a <literal>NamingStrategy</literal></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>--properties=hibernate.properties</literal></entry>
|
||||
|
@ -527,7 +576,7 @@ new SchemaValidator(cfg).validate();]]></programlisting>
|
|||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="toolsetguide-s1-7">
|
||||
<sect2 id="toolsetguide-s1-9">
|
||||
<title>Using Ant for schema validation</title>
|
||||
|
||||
<para>
|
||||
|
|
Loading…
Reference in New Issue