Skip to content

Support entity classes that are inner classes #1006

Open

Description

@mecoFarid

Describe the bug
Placing entity classes annotated with @Entity and @BaseEntity in another class will result in an error when building.

Basic info (please complete the following information):

  • ObjectBox version: 2.9.1
  • Reproducibility: always
  • Device: N/A (compile time error)
  • OS: N/A (Android library)

To Reproduce
Steps to reproduce the behavior:
1. Create the following hierarchy of classes and build

public class Holder {
    @BaseEntity
    public static abstract class Parent {
        @Id
        long boxId;
        private String text;

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }
    }

    @Entity
    public static class Child extends Parent {
    }
}

Logs, stack traces
Won't provide because this won't help in any way as IDE's build errors will be much clearer when dev-team build it themselves

Activity

  1. greenrobot-team commented on Aug 31, 2021

    @greenrobot-team
    Member

    Thanks for reporting! This is due to generated code missing imports of the inner class (error: cannot find symbol).

    A workaround is to make at least the @Entity class a top-level class.

    Internal issue objectbox-java#159

    For anyone else affected, it helps us prioritize issues if you thumbs up the first post (GitHub can sort issues by thumbs ups)!

  2. changed the title [-]ObjectBox fails to generate classes if `entity` classes are static inner class of another class[/-] [+]Support entity classes that are inner classes[/+] on May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions