Skip to content

Commit f9b9825

Browse files
Docs: add for DbDetachedException and Box.attach
1 parent e4f2ffa commit f9b9825

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

objectbox-java/src/main/java/io/objectbox/Box.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@
3030

3131
import io.objectbox.annotation.Backlink;
3232
import io.objectbox.annotation.Id;
33-
import io.objectbox.annotation.apihint.Beta;
3433
import io.objectbox.annotation.apihint.Experimental;
3534
import io.objectbox.annotation.apihint.Internal;
3635
import io.objectbox.exception.DbException;
@@ -642,7 +641,14 @@ public synchronized EntityInfo<T> getEntityInfo() {
642641
return entityInfo;
643642
}
644643

645-
@Beta
644+
/**
645+
* Attaches the given object to this.
646+
* <p>
647+
* This typically should only be used when <a
648+
* href="https://docs.objectbox.io/advanced/object-ids#self-assigned-object-ids">manually assigning IDs</a>.
649+
*
650+
* @param entity The object to attach this to.
651+
*/
646652
public void attach(T entity) {
647653
if (boxStoreField == null) {
648654
try {

objectbox-java/src/main/java/io/objectbox/exception/DbDetachedException.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,23 @@
1616

1717
package io.objectbox.exception;
1818

19+
/**
20+
* This exception occurs while working with a {@link io.objectbox.relation.ToMany ToMany} or
21+
* {@link io.objectbox.relation.ToOne ToOne} of an object and the object is not attached to a
22+
* {@link io.objectbox.Box Box} (technically a {@link io.objectbox.BoxStore BoxStore}).
23+
* <p>
24+
* If your code uses <a href="https://docs.objectbox.io/advanced/object-ids#self-assigned-object-ids">manually assigned
25+
* IDs</a> make sure it takes care of some things that ObjectBox would normally do by itself. This includes
26+
* {@link io.objectbox.Box#attach(Object) attaching} the Box to an object before modifying a ToMany.
27+
* <p>
28+
* Also see the documentation about <a href="https://docs.objectbox.io/relations#updating-relations">Updating
29+
* Relations</a> and <a href="https://docs.objectbox.io/advanced/object-ids#self-assigned-object-ids">manually assigned
30+
* IDs</a> for details.
31+
*/
1932
public class DbDetachedException extends DbException {
2033

2134
public DbDetachedException() {
22-
this("Cannot perform this action on a detached entity. " +
23-
"Ensure it was loaded by ObjectBox, or attach it manually.");
35+
this("Entity must be attached to a Box.");
2436
}
2537

2638
public DbDetachedException(String message) {

0 commit comments

Comments
 (0)