question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ToOne<target> field is package-private ? Need to use getter / setter to work.

See original GitHub issue

Basics

  • 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:closed
  • Created 6 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lucassales2commented, Sep 11, 2017

Error is gone! Its working now, thanks

0reactions
greenrobotcommented, Sep 10, 2017

1.0.1 is published - please retest, thank you!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found