Skip to content

Commit 5ed7b2d

Browse files
committed
HHH-4396 - Ability to patternize embedded column names
1 parent 99cf59a commit 5ed7b2d

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

hibernate-core/src/main/java/org/hibernate/annotations/EmbeddedColumnNaming.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,50 @@
1717
* Allows specifying a pattern to be applied to the naming of columns for
1818
* a particular {@linkplain jakarta.persistence.Embedded embedded mapping}.
1919
* For example, given a typical embeddable named {@code Address} and
20-
* {@code @Embedded @EmbeddedColumnNaming("home_%s)}, we will get columns named
20+
* {@code @EmbeddedColumnNaming("home_%s)}, we will get columns named
2121
* {@code home_street}, {@code home_city}, etc.
22+
* <p/>
23+
* Explicit {@linkplain jakarta.persistence.Column @Column(name)} mappings are incorporated
24+
* into the result. When embeddables are nested, the affect will be cumulative. Given the following model:
25+
*
26+
* <pre>
27+
* &#64;Entity
28+
* class Person {
29+
* ...
30+
* &#64;Embedded
31+
* &#64;EmbeddedColumnNaming("home_%s")
32+
* Address homeAddress;
33+
* &#64;Embedded
34+
* &#64;EmbeddedColumnNaming("work_%s")
35+
* Address workAddress;
36+
* }
37+
*
38+
* &#64;Embeddable
39+
* class Address {
40+
* &#64;Column(name="line1")
41+
* String street;
42+
* ...
43+
* &#64;Embedded
44+
* &#64;EmbeddedColumnNaming("zip_%s")
45+
* ZipPlus4 zip;
46+
* }
47+
*
48+
* &#64;Embeddable
49+
* class ZipPlus4 {
50+
* &#64;Column(name="zip_code")
51+
* String zipCode;
52+
* &#64;Column(name="plus_code")
53+
* String plusCode;
54+
* }
55+
* </pre>
56+
* Will result in the following columns:<ol>
57+
* <li>{@code home_line1}</li>
58+
* <li>{@code home_zip_zip_code}</li>
59+
* <li>{@code home_zip_plus_code}</li>
60+
* <li>{@code work_line1}</li>
61+
* <li>{@code work_zip_zip_code}</li>
62+
* <li>{@code work_zip_plus_code}</li>
63+
* </ol>
2264
*
2365
* @since 7.0
2466
* @author Steve Ebersole
@@ -33,7 +75,8 @@
3375
* <p/>
3476
* The {@code value} may be omitted which will indicate to use the pattern
3577
* {@code "{ATTRIBUTE_NAME}_%s"} where {@code {ATTRIBUTE_NAME}} is the name of the attribute
36-
* where the annotation is placed.
78+
* where the annotation is placed - e.g. {@code @Embedded @EmbeddedColumnNaming Address homeAddress}
79+
* would create columns {@code homeAddress_street}, {@code homeAddress_city}, etc.
3780
*/
3881
String value() default "";
3982
}

0 commit comments

Comments
 (0)