Maintaining relationships between tables

classic Classic list List threaded Threaded
8 messages Options
akritibahal91 akritibahal91
Reply | Threaded
Open this post in threaded view
|

Maintaining relationships between tables

Hi,

I want to know if there is any way of maintaining relationships between database tables (stored in caches) in Ignite?

Example:

Department Table has fields : deptid and dept
Employee Table has fields : id, firstname, lastname, deptid

Now, if any change in the Department Table is made (say, deptid of a department is changed), will it be reflected in the Employee table as well?
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Maintaining relationships between tables

Hi,

You're storing departments and employees as separate objects, right? If so, then there is nothing to update in Employee when Department is updated. After any update, all SQL queries will work on the new data (like in any database), so if you join two tables, you will get new results.

Makes sense?

-Val
tusharnakra tusharnakra
Reply | Threaded
Open this post in threaded view
|

Re: Maintaining relationships between tables

This post was updated on .
I don't understand, could you explain me a bit more by example or something? Do you mean first update the department table and then perform a join?
Pavel Tupitsyn Pavel Tupitsyn
Reply | Threaded
Open this post in threaded view
|

Re: Maintaining relationships between tables

Hi, 

Are you talking about foreign key constraint of some sort?

On Mon, Apr 18, 2016 at 5:49 AM, tusharnakra <[hidden email]> wrote:
I don't understand, could you explain me a bit more by example or something?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Maintaining-relationships-between-tables-tp4236p4266.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

akritibahal91 akritibahal91
Reply | Threaded
Open this post in threaded view
|

Re: Maintaining relationships between tables

Yes, could you explain how do I maintain relationships a bit more? I'm not clear on this part.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Maintaining relationships between tables

Hi,

If you're going to use SQL queries, you can organize your data model like you would do it in a relational database. In your case you can have departmentId field in Employee class and use this field to join tables. If you update Department, there is nothing to update in the Employee, because they are still linked with each other.

You can refer to query example [1] for better understanding.

[1] https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java

-Val
akritibahal91 akritibahal91
Reply | Threaded
Open this post in threaded view
|

Re: Maintaining relationships between tables

I meant, for example we had to change a deptid for a particular department. Then this is changed in the department table. Now, this deptid should be updated in the employee table as well right, for all those employees who had the previous deptid.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Maintaining relationships between tables

ID is usually used as a cache key, so it's similar to primary key in relational database.  It should not and cannot be changed without creating a new entry in the cache.

But generally you can atomically update two entries by enlisting them into one transaction [1].

[1] https://apacheignite.readme.io/docs/transactions

-Val