Skip to content

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

@GerritDeMeulder

Description

@GerritDeMeulder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions