0

I've seen a lot of Kundera examples where the object being store is fairly simple. You have something like a Car.class and it contains a couple String variables maybe an int mapped using the @Column annotation. I've even seen some List, Set and Map variables as well as the cqlsh to create a column of those types.

What I haven't seen is a custom object I created within an object and how that would be represented in a Cassandra DB.

For example:

public Class ContainerShip {

    @Column(name="container")
    Container myContainer;
}

public Class Container {
    @Column(name="containerName)
    String containerName;
}

Could I store ContainerShip into Cassandra, using Kundera with em.persist(myShip)?

If I can what would the cqlsh for creating the "container" column look like?

Justin
  • 859
  • 4
  • 15
  • 30

1 Answers1

2

You may embed a container object as an embeddable entity.

@Entity public Class ContainerShip {

@Column(name="container")
@Embedded
Container myContainer;

}

@Embeddable public Class Container {

@Column(name="containerName)
String containerName;

}

vivek mishra
  • 1,162
  • 8
  • 16
  • Interesting. So what would the type of the column in Cassandra be then for the Container? – Justin Jan 16 '14 at 20:20
  • It would store container name as a column within containership column family. Basically if looking to embed a custom object or collection of object would mean adding more columns(wide rows) or creating references(same as RDBMS associations). Kundera provides both the ways to embed a custom object as a super column or as composite/compound key. – vivek mishra Jan 17 '14 at 05:00
  • What version of Kundera are you using? 2.8.1 doesn't seem to work although I took your example a little further. I tried doing this @Column(name = "location")@Embedded private List containers. Created the column in cql as "location list". Got NPE(after first commenting out kundera.ddl.auto.prepare) in Kundera's PropertyAccessorHelper. It's a complicated case but I can't recommend Cassandra/Kundera over SQLServer/hibernate if I can't map a list of other objects ;-) – Justin Jan 17 '14 at 18:18
  • List needs to be annotated with @ElementCollection Also, with current Kundera implementation such embedded object would be treated as super columns. If you want to use Cassandra collection support, simply define your object as Map,List and Set. As far as custom objects are concerned, create a list of blob and serialize at client level to store as byte[]. Kundera doesn't serialize/deserialze such objects for you. To recommend Cassandra over SQLServer, you must be having reasons other than custom objects as well. – vivek mishra Jan 20 '14 at 05:50