How to avoid duplication of objects in the DB4o database

Student s1 = new Student();
        s1.rollNo = "44";
        s1.name = "kk";
db4o().save(s1);

Student s2 = new Student();
        s2.rollNo = "44";
        s2.name = "kk";
db4o().save(s2);

here I save two objects s1 and s2 in the DB4o database, and both objects are saved even if they have duplicate information, what I want is the same rollNo student should only be saved once, as relational databases using primary the key. I know that DB4o saves objects based on the reference address, correct me if I am wrong. Please let me know if there is a way to get primary key functionality to avoid data redundancy in DB4o.

thanks

+4
source share
2 answers

db4o . , "", . , . , :

Student toUpdate = db4o.query(new Predicate<Student>() {
    @Override
    public boolean match(Student student) {
        return pilot.rollNo.equals("44");
    }
}).get(0);

toUpdate.name ="newName";

db4o.store(toUpdate); // Updated

. db4o allway . .

, , . . : http://community.versant.com/documentation/reference/db4o-8.1/java/reference/Content/basics/update_concept.htm

+2

2 :

, .

+1

Source: https://habr.com/ru/post/1527214/


All Articles