Skip to content

Commit 9a990e5

Browse files
TargetIdProperty: improve documentation, add code example
1 parent d4d341a commit 9a990e5

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

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

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

2424
/**
25-
* Defines the property serving as the target ID of a ToOne.
26-
* This allows exposing an explicit property, which may be convenient for other parsers/serializers (e.g. JSON).
25+
* For a ToOne, changes the name of the property to store the target object ID in from the default name:
26+
* <p>
27+
* <pre>{@code
28+
* @Entity
29+
* public class Order {
30+
* @TargetIdProperty("customerRenamedTargetId")
31+
* ToOne<Customer> customer;
32+
* long customerRenamedTargetId;
33+
* }
34+
* }</pre>
35+
* <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.
39+
* <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+
* <p>
43+
* See the <a href="https://docs.objectbox.io/relations">relations documentation</a> for details.
2744
*/
2845
@Retention(RetentionPolicy.CLASS)
2946
@Target({ElementType.FIELD, ElementType.TYPE})

0 commit comments

Comments
 (0)