Create simple index for a Id field

#1

Hello, I just wanted to write another anotation to my key field so I can have a really simple index. This is the original code:

@Entity
public class ObjectDbEntity<Key,Value> implements DataItemProvider<Value> {
   
    @Id
    private Key key = null;
    private Value value = null;

and I just want my key to be indexed on my db, just like this:

@Entity
public class ObjectDbEntity<Key,Value> implements DataItemProvider<Value> {
  
    @Id
    @Index
    private Key key = null;
    private Value value = null;

How can achieve this? It's obvious there must be something wrong, but I haven't found ouy why.

Thanks in advance. Greatings

#2

As far as I know, the @Id is indexed by default, so you don't have to create an index for the id.

#3

The thing is that I noticed it's really fast inserting the elements, but when it comes to read seems like the performance falls. I can understand that reading is a complex task, because you first have to lookup and then retrieve the object, but still too slow in my opinion.
Notice I have a db with at least 1M objects, the only way I want to retrieve objects is by the key (or ID).

Maybe ObjectDB is not the best option if I want to perform massive reads?

#4

ObjectDB is faster than other DBMS, not just in writing but also in retrieval and reading operations (see this comparison). But obviously a HashMap in memory is faster than any DBMS for simple direct lookup operations.

Using a DBMS (ObjectDB or other) provides many advantages, including persistence, advanced queries, transactions, etc. but you may still want to manage your own HashMap cache in memory for specific objects if you need the extra performance.

But note that your post provides very few details. It is unclear what you are really doing, so it is impossible to provide further help. Could you please explain the scenario in more details? Could you provide exact performance information? Maybe a small test case that demonstrates your case?

ObjectDB Support

Reply