Let's try to answer your questions:
Do I really not notice the point here?
No. You can think of noSQL CB as a persistent cache of distributed objects. So this is not RDBMS. However, the DAO pattern fits perfectly into this model ... since you are dealing with DTOs / ValueObjects / POJO at the DAO and noSQL level.
I can’t imagine everyone doing this?
I suggest writing one universal Couchbase manager class that can save / retrieve POJOs. Then you can reuse it in your DAOs.
Anyone who writes methods that convert documents into POJO model classes for each class separately? Or use a json parser for this (but this will not work for foreign keys unless I load them too)?
You may have one common code in your Couchbase manager class that does the conversion from / to json to POJO. Thus, you only work with POJO and don’t see json in your application code (outside the Couchbase manager class) Here is an example of such a class:
public class CouchbaseManager<K, V> { private final Class<V> valueTypeParameterClass; @Inject private CouchbaseClient cbClient; @Inject private Gson gson; public CouchbaseManager(final Class<V> valueClass) { this.valueTypeParameterClass = valueClass; } public V get(K key) { V res = null; String jsonValue = null; if (key != null) { jsonValue = (String) cbClient.get(key); if (jsonValue != null) { res = gson.fromJson(jsonValue, valueTypeParameterClass); } } return res; } public void put(K key, V value) { int ttl = 0; cbClient.set(key, ttl, gson.toJson(value, valueTypeParameterClass)); } }
Then, in your DAO code, you create an instance of CouchbaseManager for each type:
CouchbaseManager<String,Customer> cbmCustomer = new CouchbaseManager<String,Customer>(Customer.class); CouchbaseManager<String,Account> cbmAccount = new CouchbaseManager<String,Account>(Account.class);
Now about the "foreign keys." Remember that this is not RDBMS, so there is a concept of a “foreign key” before your code. For example, the Customer class may have an account identifier:
Customer cust = cbmCustomer.get("cust-1234"); String accId = cust.getAccountId(); //You can load account Account acc = cbmAccount.get(accId);
So, as you see, you do everything yourself. I would like it to be a JPA or JDO implementation / provider for Couchbase (e.g. DataNucleus or Hibernate )
You really have to start with your POJO / Document project to try to split the POJO objects into “pieces” of data in order to get the right balance between coarse and fine-grained POJOs. Also see this discussion for key / document design considerations .