Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
5c2909dd
Commit
5c2909dd
authored
9 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Simple key example
parent
16490992
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Doc/Persist/topics.xml
+86
-1
86 additions, 1 deletion
Doc/Persist/topics.xml
with
86 additions
and
1 deletion
Doc/Persist/topics.xml
+
86
−
1
View file @
5c2909dd
...
...
@@ -399,7 +399,92 @@ public class Airline {
<section
xml:id=
"persistSectAirlineSimpleKey"
>
<title>
Advocating simple key definitions
</title>
<para/>
<qandaset
defaultlabel=
"qanda"
xml:id=
"persistQandaAirlineKeyAutoIncrementSimple"
>
<qandadiv>
<qandaentry>
<question>
<para>
We might choose a simpler model to achieve non-nullable
keys:
</para>
<programlisting
language=
"java"
>
@Entity
public class Airline {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
Long id;
@Column(unique=true, nullable=false)
String name;
@Column(unique=true, nullable=false)
String icaoCode;
public Airline(final String name, final String icaoCode) {
this.name = name;
this.icaoCode = icaoCode;
}
protected Airline(){}
}
</programlisting>
<para>
Discuss the pros and cons of this approach compared to
<xref
linkend=
"persistQandaAirlineKeyAutoIncrement"
/>
.
</para>
</question>
<answer>
<glosslist>
<glossentry>
<glossterm>
Pros:
</glossterm>
<glossdef>
<orderedlist>
<listitem>
<para>
This approach is easier to understand.
</para>
</listitem>
<listitem>
<para>
Stable approach with respect to
<xref
linkend=
"glo_Java"
/>
code refactoring: If e.g. the
property
<property>
icaoCode
</property>
gets
consistently renamed to
<property>
icaoCode
</property>
Number
<xref
linkend=
"glo_SqlDdl"
/>
code will still be properly
generated. However this problem may be overcome by
providing stable
<xref
linkend=
"glo_SqlDdl"
/>
attribute names via
<code>
@Column(name="icaoCode"
...)
</code>
thereby protecting the database from
unnecessary schema evolution issues being inflicted by
<xref
linkend=
"glo_Java"
/>
code refactoring.
</para>
</listitem>
</orderedlist>
</glossdef>
</glossentry>
<glossentry>
<glossterm>
Cons:
</glossterm>
<glossdef>
<orderedlist>
<listitem>
<para>
Does not work for composed keys.
</para>
</listitem>
<listitem>
<para>
Does not allow for self explanatory constraint
names. We end up with e.g. :
</para>
<programlisting
language=
"sql"
>
...
UNIQUE KEY `UK_s759kv0st7r42c85xqjjiusde` (`icaoCode`),
UNIQUE KEY `UK_swdntm8xd26ugm3t78mkkted2` (`name`)
...
</programlisting>
</listitem>
</orderedlist>
</glossdef>
</glossentry>
</glosslist>
</answer>
</qandaentry>
</qandadiv>
</qandaset>
</section>
</section>
</chapter>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment