You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by akritibahal91 <ak...@outlook.com> on 2016/04/15 21:05:19 UTC

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?



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

Re: Maintaining relationships between tables

Posted by vkulichenko <va...@gmail.com>.
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



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

Re: Maintaining relationships between tables

Posted by akritibahal91 <ak...@outlook.com>.
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.



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

Re: Maintaining relationships between tables

Posted by vkulichenko <va...@gmail.com>.
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



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

Re: Maintaining relationships between tables

Posted by akritibahal91 <ak...@outlook.com>.
Yes, could you explain how do I maintain relationships a bit more? I'm not
clear on this part.



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

Re: Maintaining relationships between tables

Posted by Pavel Tupitsyn <pt...@gridgain.com>.
Hi,

Are you talking about foreign key constraint of some sort?

On Mon, Apr 18, 2016 at 5:49 AM, tusharnakra <tu...@hotmail.com>
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.
>

Re: Maintaining relationships between tables

Posted by tusharnakra <tu...@hotmail.com>.
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.

Re: Maintaining relationships between tables

Posted by vkulichenko <va...@gmail.com>.
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



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