@@ -1555,29 +1555,28 @@ public class User {
1555
1555
</p >
1556
1556
</subsection >
1557
1557
1558
- <subsection name =" Auto-mapping " >
1558
+ <subsection name =" 自動マッピング " >
1559
1559
1560
1560
<p >
1561
- As you have already seen in the previous sections, in simple cases MyBatis can auto-map the results for you
1562
- and in others you will need to build a result map.
1563
- But as you will see in this section you can also mix both strategies.
1564
- Let's have a deeper look at how auto-mapping works.
1561
+ 前章では、シンプルなケースでは MyBatis の自動マッピングが利用できるということと、複雑なケースではあなた自身で Result Map を記述する必要があるということを説明しました。
1562
+ この章では更に、この2つの方法を同時に利用する方法を説明していきます。
1563
+ まず、自動マッピングの動作について詳しく見て行きましょう。
1565
1564
</p >
1566
1565
1567
1566
<p >
1568
- When auto-mapping results MyBatis will get the column name and look for a property with the same name ignoring case. That means that if
1569
- a column named <i >ID</i > and property named <i >id</i > are found, MyBatis will set the <i >id</i > property with the <i >ID</i > column value.
1567
+ 結果を自動マッピングする際、 MyBatis は列名と同じ名前を持つプロパティを探します(大文字と小文字は区別しません)。
1568
+ 例えば <i >ID</i > という名前の列と <i >id</i > という名前のプロパティが見つかった場合、 MyBatis は <i >id</i > プロパティに <i >ID</i > 列の値をセットします。
1570
1569
</p >
1571
1570
1572
1571
<p >
1573
- Usually database columns are named using uppercase letters and underscores between words and java properties often follow the camelcase
1574
- naming covention. To enable the auto-mapping between them set the setting <code >mapUnderscoreToCamelCase</code > to true.
1572
+ 通常、データベースの列名は英数字と単語を区切るアンダースコアで定義され、Java のプロパティはキャメルケースで定義されるのが一般的です。
1573
+ <code >mapUnderscoreToCamelCase</code > に true に設定すると、この一般的な命名規則に基づいて自動マッピングを適用することができます。
1575
1574
</p >
1576
1575
1577
1576
<p >
1578
- Auto-mapping works even when there is an specific result map. When this happens, for each result map, all columns that are present in the
1579
- ResultSet that have not a manual mapping will be auto-mapped, then manual mappings will be processed.
1580
- In the following sample < i >id</ i > and < i >userName</ i > columns will be auto-mapped and < i >hashed_password</ i > column will be mapped. </p >
1577
+ Result Map が指定されている場合でも自動マッピングは動作します。この場合、ResultSet に含まれる列のうち、各 Result Map で明示的にマッピングが指定されていない列が自動マッピングの対象となります。
1578
+ 次の例では、< i >hashed_password</ i > 列が password プロパティにマップされ、< i >id</ i > と < i >userName</ i > 列が自動マッピングの対象となります。
1579
+ </p >
1581
1580
1582
1581
<source ><![CDATA[ <select id="selectUsers" parameterType="int" resultType="User">
1583
1582
select
@@ -1593,25 +1592,25 @@ public class User {
1593
1592
</resultMap>]]> </source >
1594
1593
1595
1594
<p >
1596
- There are three auto-mapping levels:
1595
+ 自動マッピングには3つのレベルがあります。
1597
1596
</p >
1598
1597
1599
1598
<ul >
1600
1599
<li >
1601
- <code >NONE</code > - disables auto-mapping. Only manually mapped properties will be set.
1600
+ <code >NONE</code > - 自動マッピングを無効化します。明示的にマッピングが指定されたプロパティにのみ値がセットされます。
1602
1601
</li >
1603
1602
<li >
1604
- <code >PARTIAL</code > - will auto-map results except those that have nested result mappings defined inside (joins).
1603
+ <code >PARTIAL</code > - ネストされた Result Map を持たない Result Map のみが自動マッピングの対象となります。
1605
1604
</li >
1606
1605
<li >
1607
- <code >FULL</code > - auto-maps everything.
1606
+ <code >FULL</code > - 全ての Result Map が自動マッピングの対象となります。
1608
1607
</li >
1609
1608
</ul >
1610
1609
1611
1610
<p >
1612
- The default value is <code >PARTIAL</code >, and it is so for a reason. When < code >FULL</ code > is used auto-mapping will
1613
- be performed when processing join results and joins retrieve data of several different entities in the same row
1614
- hence this may result in undesired mappings. To understand the risk have a look at the following sample:
1611
+ デフォルト値は <code >PARTIAL</code > で、それには理由があります。
1612
+ < code >FULL</ code > が指定されていると、JOIN 句によって複数のエンティティに対する結果が一行に結合されているような場合に自動マッピングによって意図しないマッピングが実行されてしまう場合があります。
1613
+ 次の例を見てください。
1615
1614
</p >
1616
1615
1617
1616
<source ><![CDATA[ <select id="selectBlog" parameterType="int" resultMap="blogResult">
@@ -1632,9 +1631,8 @@ public class User {
1632
1631
</resultMap>]]> </source >
1633
1632
1634
1633
<p >
1635
- With this result map both <i >Blog</i > and <i >Author</i > will be auto-mapped. But note that <i >Author</i > has an <i >id</i >
1636
- property and there is a column named <i >id</i > in the ResultSet so Author's id will be filled with Blog's id, and that is not
1637
- what you were expecting. So use the <code >FULL</code > option with caution.
1634
+ この Result Map では、<i >Blog</i > と <i >Author</i > の両方が自動マッピングの対象となりますが、<i >Author</i > に <i >id</i > というプロパティがあり、ResultSet に <i >id</i > という列が含まれているため、Author の id に Blog の id がセットされることになります。
1635
+ 自動マッピングで <code >FULL</code > を指定する場合は、こうした意図しないマッピングが行われないように注意する必要があります。
1638
1636
</p >
1639
1637
1640
1638
</subsection >
0 commit comments