Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem to retrieve objects of sub-relation Cassandra with Kundera (Pelops - JPA) #717

Closed
mateusleonardi opened this issue Mar 11, 2015 · 3 comments

Comments

@mateusleonardi
Copy link

We are getting a null object while retrieving data from Cassandra using JPA annotation OneToOne/OneToMany (see example below, where "item" is null).


[
{
"idProduct":"095102f1-a987-4f7c-88c3-153d80b6977f",
"item":{
"idItem":"b75acb06-eab6-48c1-99e9-fc7d48cf930b",
"shortDescription":"Item 71",
"longDescription":"An another item 71",
"name":"Item Named 71",
"image":"Image 71"
},
"options":[
{
"idProductOption":"0fa701dc-5394-47ea-86f6-e3dbf6c263da",
"idProduct":"095102f1-a987-4f7c-88c3-153d80b6977f",
"productOptionValue":[
{
"idProductOptionValue":"1b594b56-7767-4909-9d16-add51903c0f2",
"idProductOption":"0fa701dc-5394-47ea-86f6-e3dbf6c263da",
"item":null
}
]
}
]
}

]

If we access "ProductOptionValue" directly it loads perfectly.

See it loading correctly (so, we think that's a level limitation to load).

[
{
"idProductOptionValue":"1b594b56-7767-4909-9d16-add51903c0f2",
"idProductOption":"0fa701dc-5394-47ea-86f6-e3dbf6c263da",
"item":{
"idItem":"17803826-0be6-4b94-813d-76abf969fa97",
"shortDescription":"Item 41",
"longDescription":"An item 41",
"name":"Item Named 41",
"image":"Image 41"
}
}

]

We are using the following annotations to relate the objects.

@Entity
@Table(name = "Product",  schema = "kunderaexamples@cassandra_pu")
public class Product {
    @Id
    @Column(name = "idProduct")
    private String idProduct;

    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    private List<ProductOption> productOption;

    @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @JoinColumn(name = "idItem", table = "Item")
    private Item item;

    public String getIdProduct() {
        return idProduct;
    }

    public void setIdProduct(String idProduct) {
        this.idProduct = idProduct;
    }

    public List<ProductOption> getOptions() {
        return productOption;
    }

    public void setOptions(List<ProductOption> options) {
        this.productOption = options;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public Product() {
    }
}

@Entity
@Table(name = "ProductOption",  schema = "kunderaexamples@cassandra_pu")
public class ProductOption {
    @Id
    @Column(name = "idProductOption")
    private String idProductOption;

    @Column(name = "idProduct")
    private String idProduct;

    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    private List<ProductOptionValue> productOptionValue;

    public String getIdProductOption() {
        return idProductOption;
    }

    public void setIdProductOption(String idProductOption) {
        this.idProductOption = idProductOption;
    }

    public List<ProductOptionValue> getProductOptionValue() {
        return productOptionValue;
    }

    public void setProductOptionValue(List<ProductOptionValue> productOptionValues) {
        this.productOptionValue = productOptionValues;
    }

    public String getIdProduct() {
        return idProduct;
    }

    public void setIdProduct(String idProduct) {
        this.idProduct = idProduct;
    }

    public ProductOption() {
    }
}

@Entity
@Table(name = "ProductOptionValue",  schema = "kunderaexamples@cassandra_pu")
public class ProductOptionValue {
    @Id
    @Column(name = "idProductOptionValue")
    private String idProductOptionValue;

    @Column(name = "idProductOption")
    private String idProductOption;

    @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @JoinColumn(name = "idItem", table = "Item")
    private Item item;

    public String getIdProductOptionValue() {
        return idProductOptionValue;
    }

    public void setIdProductOptionValue(String idProductOptionValue) {
        this.idProductOptionValue = idProductOptionValue;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public String getIdProductOption() {
        return idProductOption;
    }

    public void setIdProductOption(String idProductOption) {
        this.idProductOption = idProductOption;
    }

    public ProductOptionValue() {
    }
}

@Entity
@Table(name = "Item",  schema = "kunderaexamples@cassandra_pu")
public class Item {
    @Id
    @Column(name = "idItem")
    private String idItem;

    @Column(name = "short_description")
    private String shortDescription;

    @Column(name = "long_description")
    private String longDescription;

    @Column(name = "name")
    private String name;

    @Column(name = "image")
    private String image;

//  @Column(name = "context")
//  private Context context;
//  
//  @Column(name = "inventory")
//  private Inventory inventory;
//  
//  @Column(name = "price")
//  private ItemPrice price;

    /*
     * GETTERS AND SETTERS
     * */
    public String getIdItem() {
        return idItem;
    }

    public void setIdItem(String idItem) {
        this.idItem = idItem;
    }

    public String getShortDescription() {
        return shortDescription;
    }

    public void setShortDescription(String shortDescription) {
        this.shortDescription = shortDescription;
    }

    public String getLongDescription() {
        return longDescription;
    }

    public void setLongDescription(String longDescription) {
        this.longDescription = longDescription;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

//  public Context getContext() {
//      return context;
//  }
//
//  public void setContext(Context context) {
//      this.context = context;
//  }
//
//  public Inventory getInventory() {
//      return inventory;
//  }
//
//  public void setInventory(Inventory inventory) {
//      this.inventory = inventory;
//  }
//
//  public ItemPrice getPrice() {
//      return price;
//  }
//
//  public void setPrice(ItemPrice price) {
//      this.price = price;
//  }

    public Item() {
    }
}
@amit-kr
Copy link
Collaborator

amit-kr commented Mar 12, 2015

@mateusleonardi,

Which version of Kundera-client are you using?
Please specify @joincolumn annotation with @OneToMany as well. I tried doing same and retrieved data via em.find() and it works at my end. Also, any specific reason for using Peolps client and not ThriftClientFactory?

HTH
Amit

@chhavigangwal chhavigangwal added this to the 3.0 milestone May 11, 2015
@chhavigangwal chhavigangwal modified the milestones: 3.1, 3.0 Aug 27, 2015
@chhavigangwal chhavigangwal modified the milestones: 3.2, 3.1 Nov 2, 2015
@karthikprasad13
Copy link
Collaborator

@mateusleonardi

Any updates?

-Karthik

@mateusleonardi
Copy link
Author

We are not using Kundera, we migrate to DataStax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants