Skip to content

Commit a8a3f9b

Browse files
committed
HHH-7626 - Add javadoc to annotations
1 parent 5aad2bf commit a8a3f9b

15 files changed

+182
-32
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
* Prefer the standard {@link javax.persistence.Access} annotation
3737
*
3838
* @author Emmanuel Bernard
39+
*
40+
* @deprecated Use {@link AttributeAccessor} instead; renamed to avoid confusion with the JPA
41+
* {@link javax.persistence.AccessType} enum.
3942
*/
4043
@Target({ TYPE, METHOD, FIELD })
4144
@Retention(RUNTIME)
45+
@Deprecated
4246
public @interface AccessType {
4347
String value();
4448
}

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,32 @@
3131
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3232

3333
/**
34-
* Define a ToOne association pointing to several entity types.
35-
* Matching the according entity type is doe through a metadata discriminator column
36-
* This kind of mapping should be only marginal.
37-
*
34+
* Defines a ToOne-style association pointing to one of several entity types depending on a local discriminator,
35+
* as opposed to discriminated inheritance where the discriminator is kept as part of the entity hierarchy.
36+
*
37+
* For example, if you consider an Order entity containing Payment information where Payment might be of type
38+
* CashPayment or CreditCardPayment the @Any approach would be to keep that discriminator and matching value on the
39+
* Order itself. Thought of another way, the "foreign-key" really is made up of the value and discriminator
40+
* (there is no physical foreign key here as databases do not support this):
41+
* <blockquote><pre>
42+
* &#064;Entity
43+
* class Order {
44+
* ...
45+
* &#064;Any( metaColumn = @Column( name="payment_type" ) )
46+
* &#064;AnyMetDef(
47+
* idType = "long"
48+
* metaValues = {
49+
* &#064;MetaValue( value="C", targetEntity=CashPayment.class ),
50+
* &#064;MetaValue( value="CC", targetEntity=CreditCardPayment.class ),
51+
* }
52+
* )
53+
* pubic Payment getPayment() { ... }
54+
* }
55+
* }
56+
* </pre></blockquote>
57+
*
3858
* @author Emmanuel Bernard
59+
* @author Steve Ebersole
3960
*/
4061
@java.lang.annotation.Target({METHOD, FIELD})
4162
@Retention(RUNTIME)
@@ -48,10 +69,10 @@
4869
String metaDef() default "";
4970

5071
/**
51-
* Metadata discriminator column description, This column will hold the meta value corresponding to the
52-
* targeted entity.
72+
* Identifies the discriminator column. This column will hold the value that identifies the targeted entity.
5373
*/
5474
Column metaColumn();
75+
5576
/**
5677
* Defines whether the value of the field or property should be lazily loaded or must be
5778
* eagerly fetched. The EAGER strategy is a requirement on the persistence provider runtime

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3232

3333
/**
34-
* Defines @Any and @manyToAny metadata
34+
* Used to provide metadata about an {@link Any} or {@link ManyToAny} mapping.
35+
*
36+
* @see AnyMetaDefs
3537
*
3638
* @author Emmanuel Bernard
39+
* @author Steve Ebersole
3740
*/
3841
@java.lang.annotation.Target( { PACKAGE, TYPE, METHOD, FIELD } )
3942
@Retention( RUNTIME )
@@ -45,18 +48,18 @@
4548
String name() default "";
4649

4750
/**
48-
* meta discriminator Hibernate type
51+
* Names the discriminator Hibernate Type for this Any/ManyToAny mapping. The default is to use
52+
* {@link org.hibernate.type.StringType}
4953
*/
5054
String metaType();
5155

5256
/**
53-
* Hibernate type of the id column
54-
* @return Hibernate type of the id column
57+
* Names the identifier Hibernate Type for the entity associated through this Any/ManyToAny mapping.
5558
*/
5659
String idType();
5760

5861
/**
59-
* Matching discriminator values with their respective entity
62+
* Maps discriminator values to the matching corresponding entity types.
6063
*/
6164
MetaValue[] metaValues();
6265
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
* Boston, MA 02110-1301 USA
2323
*/
2424
package org.hibernate.annotations;
25+
2526
import java.lang.annotation.Retention;
2627

2728
import static java.lang.annotation.ElementType.PACKAGE;
2829
import static java.lang.annotation.ElementType.TYPE;
2930
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3031

3132
/**
32-
* Defines @Any and @ManyToAny set of metadata.
33-
* Can be defined at the entity level or the package level
33+
* Used to group together {@link AnyMetaDef} annotations. Can be defined at the entity or package level
3434
*
3535
* @author Emmanuel Bernard
36+
* @author Steve Ebersole
3637
*/
3738
@java.lang.annotation.Target( { PACKAGE, TYPE } )
3839
@Retention( RUNTIME )
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.annotations;
25+
26+
import java.lang.annotation.Retention;
27+
28+
import static java.lang.annotation.ElementType.FIELD;
29+
import static java.lang.annotation.ElementType.METHOD;
30+
import static java.lang.annotation.ElementType.TYPE;
31+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
32+
33+
/**
34+
* Names a {@link org.hibernate.property.PropertyAccessor} strategy to use.
35+
*
36+
* Can be specified at either:<ul>
37+
* <li>
38+
* <strong>TYPE</strong> level, which will act as naming the default accessor strategy for
39+
* all attributes on the class which do not explicitly name an accessor strategy
40+
* </li>
41+
* <li>
42+
* <strong>METHOD/FIELD</strong> level, which will be in effect for just that attribute.
43+
* </li>
44+
* </ul>
45+
*
46+
* Should only be used to name custom {@link org.hibernate.property.PropertyAccessor}. For {@code property/field}
47+
* access, the JPA {@link javax.persistence.Access} annotation should be preferred using the appropriate
48+
* {@link javax.persistence.AccessType}. However, if this annotation is used with either {@code value="property"}
49+
* or {@code value="field"}, it will act just as the corresponding usage of {@link javax.persistence.Access}.
50+
*
51+
* @author Steve Ebersole
52+
* @author Emmanuel Bernard
53+
*/
54+
@java.lang.annotation.Target({ TYPE, METHOD, FIELD })
55+
@Retention(RUNTIME)
56+
public @interface AttributeAccessor {
57+
/**
58+
* Names the {@link org.hibernate.property.PropertyAccessor} strategy
59+
*/
60+
String value();
61+
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Boston, MA 02110-1301 USA
2323
*/
2424
package org.hibernate.annotations;
25+
2526
import java.lang.annotation.Retention;
2627
import java.lang.annotation.Target;
2728

@@ -31,13 +32,31 @@
3132
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3233

3334
/**
34-
* Batch size for SQL loading
35+
* Defines size for batch loading of collections or lazy entities. For example...
36+
* <blockquote><pre>
37+
* &#064;Entity
38+
* &#064;BatchSize(size=100)
39+
* class Product {
40+
* ...
41+
* }
42+
* </pre></blockquote>
43+
* will initialize up to 100 lazy Product entity proxies at a time.
44+
*
45+
* <blockquote><pre>
46+
* &#064;OneToMany
47+
* &#064;BatchSize(size = 5) /
48+
* Set<Product> getProducts() { ... };
49+
* </pre></blockquote>
50+
* will initialize up to 5 lazy collections of products at a time
3551
*
3652
* @author Emmanuel Bernard
53+
* @author Steve Ebersole
3754
*/
3855
@Target({TYPE, METHOD, FIELD})
3956
@Retention(RUNTIME)
4057
public @interface BatchSize {
41-
/** Strictly positive integer */
58+
/**
59+
* Strictly positive integer
60+
*/
4261
int size();
4362
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3131

3232
/**
33-
* Apply a cascade strategy on an association
33+
* Apply a cascade strategy on an association. Used to apply Hibernate specific cascades. For JPA cascading, prefer
34+
* using {@link javax.persistence.CascadeType} on {@link javax.persistence.OneToOne},
35+
* {@link javax.persistence.OneToMany}, etc. Hibernate will merge together both sets of cascades.
36+
*
37+
* @author Emmanuel Bernard
38+
* @author Steve Ebersole
3439
*/
3540
@Target({METHOD, FIELD})
3641
@Retention(RUNTIME)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
/**
28-
* Cascade types (can override default EJB3 cascades
28+
* Cascade types (can override default JPA cascades
2929
*/
3030
public enum CascadeType {
3131
ALL,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3232

3333
/**
34-
* Arbitrary SQL check constraints which can be defined at the class,
35-
* property or collection level
34+
* Arbitrary SQL CHECK constraints which can be defined at the class, property or collection level
3635
*
3736
* @author Emmanuel Bernard
3837
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3131

3232
/**
33-
* Names a custom collection type for a persistent collection.
33+
* Names a custom collection type for a persistent collection. The collection can also name a @Type, which defines
34+
* the Hibernate Type of the collection elements.
3435
*
3536
* @see org.hibernate.type.CollectionType
3637
* @see org.hibernate.usertype.UserCollectionType

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
* The write expression must contain exactly one '?' placeholder for the value.
3535
*
3636
* For example: <code>read="decrypt(credit_card_num)" write="encrypt(?)"</code>
37-
*
37+
*
38+
* @see ColumnTransformers
39+
*
3840
* @author Emmanuel Bernard
3941
*/
4042
@java.lang.annotation.Target({FIELD,METHOD})

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3030

3131
/**
32-
* Discriminator formula
33-
* To be placed at the root entity.
32+
* Used to apply a Hibernate formula (derived value) as the inheritance discriminator "column". Used in place of
33+
* the JPA {@link javax.persistence.DiscriminatorColumn} when a formula is wanted.
34+
*
35+
* To be placed on the root entity.
3436
*
35-
* @author Emmanuel Bernard
3637
* @see Formula
38+
*
39+
* @author Emmanuel Bernard
40+
* @author Steve Ebersole
3741
*/
3842
@Target({TYPE})
3943
@Retention(RUNTIME)

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,34 @@
3030
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3131

3232
/**
33-
* Formula. To be used as a replacement for @Column in most places
34-
* The formula has to be a valid SQL fragment
33+
* Defines a formula (derived value) which is a SQL fragment that acts as a @Column alternative in most cases.
34+
* Represents read-only state.
35+
*
36+
* In certain cases @ColumnTransformer might be a better option, especially as it leaves open the option of still
37+
* being writable.
38+
*
39+
* <blockquote><pre>
40+
* // perform calculations
41+
* &#064;Formula( "sub_total + (sub_total * tax)" )
42+
* long getTotalCost() { ... }
43+
* </pre></blockquote>
44+
*
45+
* <blockquote><pre>
46+
* // call functions
47+
* &#064;Formula( "upper( substring( middle_name, 1 ) )" )
48+
* Character getMiddleInitial() { ... }
49+
* </pre></blockquote>
50+
*
51+
* <blockquote><pre>
52+
* // this might be better handled through @ColumnTransformer
53+
* &#064;Formula( "decrypt(credit_card_num)" )
54+
* String getCreditCardNumber() { ... }
55+
* </pre></blockquote>
56+
*
57+
* @see ColumnTransformer
3558
*
3659
* @author Emmanuel Bernard
60+
* @author Steve Ebersole
3761
*/
3862
@Target({METHOD, FIELD})
3963
@Retention(RUNTIME)

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,23 @@
2222
* Boston, MA 02110-1301 USA
2323
*/
2424
package org.hibernate.annotations;
25-
import java.lang.annotation.Retention;
25+
2626
import javax.persistence.Column;
2727
import javax.persistence.FetchType;
28+
import java.lang.annotation.Retention;
2829

2930
import static java.lang.annotation.ElementType.FIELD;
3031
import static java.lang.annotation.ElementType.METHOD;
3132
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3233

3334
/**
34-
* Defined a ToMany association pointing to different entity types.
35-
* Matching the according entity type is doe through a metadata discriminator column
36-
* This kind of mapping should be only marginal.
35+
* This is the collection-valued form of @Any definitions. Defines a ToMany-style association pointing
36+
* to one of several entity types depending on a local discriminator. See {@link Any} for further information.
37+
*
38+
* @see Any
3739
*
3840
* @author Emmanuel Bernard
41+
* @author Steve Ebersole
3942
*/
4043
@java.lang.annotation.Target({METHOD, FIELD})
4144
@Retention(RUNTIME)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
*/
2424
package org.hibernate.annotations;
2525

26-
2726
/**
28-
* Represent a discriminator value associated to a given entity type
27+
* Maps a given discriminator value to the corresponding entity type. See {@link Any} for more information.
28+
*
29+
* @see Any
30+
*
2931
* @author Emmanuel Bernard
32+
* @author Steve Ebersole
3033
*/
3134
public @interface MetaValue {
3235
/**

0 commit comments

Comments
 (0)