Skip to content

[1.1.0] ToOne<Some> is null #205

@RashidMalikov

Description

@RashidMalikov
@Entity
public class Product {
    @Id
    private long id;
    private String title= "Product №";
    private String desc;
    public ToOne<Category> category;

    public ToOne<Category> getCategory() {
        return category;
    }

    public void setCategory(ToOne<Category> category) {
        this.category = category;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title= title;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
@Entity
public class Category {
    @Id
    private long id;
    private String title;

    public Category(String title) {
      this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}
boxStore.runInTx(new Runnable() {() ->
                    Category category = new Category("Stuff");
                    categoryBox.put(category);
                    Product product = new Product();
                    product.category.setTarget(category);  // product.category  NPE
                    productBox.put(product);
            });

product.category is null

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