Search code examples
javahibernatecassandraone-to-manykundera

OneToMany relationship not working


I want to create a relationship between my sensor class with pieces class using kundera as a framework and cassandra as my database:

what Im trying to do is: each sensor is associate to many pieces :

sensor 1____0 * pieces

but after doing this configuration (below), I get two separate table without any relation like this:

 idsensor | date  | event_time               | pressure | temperature
----------+-------+--------------------------+----------+-------------
        1 | 33544 | 1970-01-01 00:00:00+0000 |       10 |          10

(1 rows)
cqlsh:sensor> select * from pieces;

 idpiece | date | depth | event_time | height | idsensor | sensorkey | width
---------+------+-------+------------+--------+----------+-----------+-------
       1 | null |    12 |       null |     11 |     null |      null |    10

key class:

@Embeddable
public class SensorKey
{
    @Column 
    private String idsensor;           
    @Column 
    private long date;           
    @Column(name = "event_time")
    private long eventTime;

sensor class

   public class SensorEntitie implements Serializable {
    @EmbeddedId
    private SensorKey sensorkey;
    @Column
    private float temperature;
    @Column
    private float pressure;
    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @JoinColumns({
        @JoinColumn(name = "idsensor", referencedColumnName = "idsensor"),
        @JoinColumn(name = "date", referencedColumnName = "date",
            insertable = false, updatable = false),
        @JoinColumn(name = "event_time", referencedColumnName = "event_time",
            insertable = false, updatable = false)
})
    private Set<PieceEntitie> pieces;

pieces class:

public class PieceEntitie implements Serializable{


    @Id
    private String idpiece;
    @Column
    private double width;
    @Column
    private double height;
    @Column
    private double depth;

tutorial followed; https://github.com/impetus-opensource/Kundera/wiki/Polyglot-Persistence

how can i create this relation ?


Solution

  • Problem resolved after using Cassandra 3

    because before I used cassandra 2.1