Skip to content

Commit b46935f

Browse files
TargetIdProperty: improve code example, simplify description
1 parent 9a990e5 commit b46935f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

objectbox-java-api/src/main/java/io/objectbox/annotation/TargetIdProperty.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,25 @@
2222
import java.lang.annotation.Target;
2323

2424
/**
25-
* For a ToOne, changes the name of the property to store the target object ID in from the default name:
25+
* For a ToOne, changes the name of its associated target ID (or "relation") property.
2626
* <p>
2727
* <pre>{@code
2828
* @Entity
2929
* public class Order {
30-
* @TargetIdProperty("customerRenamedTargetId")
30+
* // Change from default "customerId" to "customerRef"
31+
* @TargetIdProperty("customerRef")
3132
* ToOne<Customer> customer;
32-
* long customerRenamedTargetId;
33+
* // Optional: expose target ID property (using changed name)
34+
* long customerRef;
3335
* }
3436
* }</pre>
3537
* <p>
36-
* By default, a target ID property named like the ToOne property with the suffix "Id" is created implicitly (so without
37-
* defining it in the @Entity class). Using the example above, without the annotation a "virtual" property named
38-
* {@code long customerId} would be created.
38+
* A target ID property is implicitly created (so without defining it in the {@link Entity @Entity} class) for each
39+
* ToOne and stores the ID of the referenced target object. By default, it's named like the ToOne field plus the suffix
40+
* "Id" (for example {@code customerId}).
3941
* <p>
40-
* Exposing the target ID as an actual field (so not necessarily renamed using this annotation) can be useful for other
41-
* parsers or serializers, like for JSON.
42+
* Like in the example above, it's still possible to expose the target ID property as an actual field (useful for other
43+
* parsers or serializers, like for JSON). But make sure to use the changed name for the field.
4244
* <p>
4345
* See the <a href="https://docs.objectbox.io/relations">relations documentation</a> for details.
4446
*/

0 commit comments

Comments
 (0)