Having worked only with MySql so far, I can't understand how to manage in MapDB what in MySql I do with foreign keys. For example, if I have two (or more) ConcurrentNavigableMap with some data (like objects), how can I relate the data between these maps? What is the mechanism? MapDB docs are too concise. Thanks
Asked
Active
Viewed 117 times
1 Answers
1
MapDB is a Key-Value Database. It does not have the notion of foreign keys. If you want to manage your data that way, your application code has to ensure that tables/maps do not contain references/keys if one key/value is deleted in the a specific map.
MapDB does not have most of the features of an SQL database, it wasn't built for that. You can check out the "embedded sql databases" in Java that exist, like Apache Derby, H2 etc. Have a look at this question and its answers: Java Embedded Databases Comparison

vasquez
- 583
- 5
- 18
-
"If you want to manage your data that way, your application code has to ensure that tables/maps do not contain references/keys if one key/value is deleted in the a specific map." How can I do ? In fact, it's exactly the problem I'm facing. In my code I assign an int id for the key value. But when I delete the last item I've put in the map, that id will result free even if it was used and if I have some other data which refers to that id this can result in an inconsistency in the datas. How can I resolve this problem? – JamieITGirl Feb 01 '18 at 10:54
-
The code needs to delete it in the other table too. Since MapDB does not have real transactions (commit/rollback is a database-wide operation without transaction isolation), you need to serialize the transactions within the code (using locks or "synchronize" etc). – vasquez Feb 06 '18 at 08:20
-
I found that Java has the Atomic.Integer class and the incrementAndGet() method which allows to set unique ids, that's worked for me. – JamieITGirl Feb 09 '18 at 19:03