-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cassandra question -- mapping multiple tables to one Entity
PostPosted: Thu Sep 24, 2015 3:23 pm 
Newbie

Joined: Thu Sep 24, 2015 3:11 pm
Posts: 1
We have a top level domain object / @Entity called Audit.

For simplicity, let's say Audit.java has 4 fields:

public class Audit{
Date date; // Will just be queried on as MM/DD/yyyy
String event;
String user;
String desc;
}

In this example, we are creating 3 different Cassandra 2.0 tables to this one entity.

AuditsByDate - Partition key is the MM/dd/yyyy date of the audit
AuditsByEvent - Partition key is the audit event name
AuditsByUser - Partition key is the audit user


Each of these tables has the same 1 row written every time an audit is written. We just want to be able to query these identical rows different ways as needed.


My newbie Cassandra / Hibernate OGM question is:

Is there a way for us to have one single OGM -annotated class that can interact with all three of these highly related tables? Is there any way to use Hibernte OGM 5.x to do something basically like this?

@Entity
@Table("AuditsByDate")
@Table("AuditsByEvent")
@Table("AuditsByUser") // Mapping it to 3 tables causes each table to have a row written in each table for every insert operation.
public class Audit{

@PartitionKey(table="AuditsByDate") // Specifying each of these partition keys lets us select from the right sub-table correctly based on which partition key was passed in
@Column(name="date")
Date date; // Will just be queried on as MM/DD/yyyy

@PartitionKey(table="AuditsByEvent") // Specifying each of these partition keys lets us select from the right sub-table correctly based on which partition key was passed in
@Column(name="event")
String event;

@PartitionKey(table="AuditsByUser") // Specifying each of these partition keys lets us select from the right sub-table correctly based on which partition key was passed in
@Column(name="user")
String user;

@Column(name="desc")
String desc;
}


Or would we need a separate OGM -annotated .java class for each of our 3 tables?

Thanks in advance!!!


Top
 Profile  
 
 Post subject: Re: Cassandra question -- mapping multiple tables to one Entity
PostPosted: Fri Sep 25, 2015 8:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Unfortunately today, Hibernate OGM does not support easily what you want.
From what I understand, you use these tables as some kind of secondary indexes w/ a materialized view on each entry. And depending on the query you want to perform, you use one or the other of the tables.

We want to have that kind of capability in OGM at some point: declaratively denormalize how the data is stored and have the query engine use the best denormalized form, but we are not there yet. In the mean time indeed, you would need to create three entities which is inconvenient.

I'm tempted to say though that your use case might be solvable by Cassandra secondary indexes, am I missing something?

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.