ToOne<target> field is package-private ? Need to use getter / setter to work.
See original GitHub issueBasics
- ObjectBox version : 0.9.15
- Reproducibility: always
Reproducing the bug
Description
If you have data-models in one package and access them from another package, and use a ToOne relation in an entity without explicit (and normally redundant) “public” (since the entity itself is public + as in online documentation) setTarget etc. don’t work, since the ToOne<target> field is package-private you need to explicitly declare “public” ToOne relation in an entity, to get “setTarget” to work.
Code
package com.objectboxtest.model;`
@Entity
public class User {
@Id
long id;
PUBLIC ToOne<Organization> organization;
...
then accessing :
package com.objectboxtest.activities;
...
organization1 = new Organization();
organization1.setName("Organization 1");
organizationsBox.put(organization1);
User user1 = new User();
user1.organization.setTarget(organization1);
....
-> works Following :
package com.objectboxtest.model;
@Entity
public class User {
@Id
long id;
ToOne<Organization> organization;
...
then accessing
package com.objectboxtest.activities;
...
organization1 = new Organization();
organization1.setName("Organization 1");
organizationsBox.put(organization1);
User user1 = new User();
user1.organization.setTarget(organization1);
....
-> does not work, organization for user 1 is not found, since it’s not public
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Getter Setter: To Use or Not to Use? - DZone
All fields should be kept private, but, setters should only be kept private when it makes sense, which makes that object Immutable.
Read more >@Getter and @Setter - Project Lombok
This lets you override the behaviour of a @Getter , @Setter or @Data annotation on a class. To put annotations on the generated...
Read more >Why does GSON use fields and not getters/setters?
Generally speaking when you serialize/deserialize an object, you are doing so to end up with an exact copy of the state of the...
Read more >Significance of Getters and Setters in Java - Baeldung
Getters and Setters play an important role in retrieving and updating the value of a variable outside the encapsulating class.
Read more >Java Encapsulation and Getters and Setters - W3Schools
Get and Set. You learned from the previous chapter that private variables can only be accessed within the same class (an outside class...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Error is gone! Its working now, thanks
1.0.1 is published - please retest, thank you!