简体   繁体   中英

OrientDB Custom Type Storing as Boolean

I have been working with the OrientDB Object database lately, but I have hit an odd stumbling point. Some of the objects I want to store have BigIntegers as members and for some reason they are storing in the database as Boolean. I attempted to use the sample code found here . I have a short sample and my Maven dependencies to demonstrate below, but here are my two questions:

For the sake of getting this to work, why does this not work?

For the sake of better understanding, how is it coming up with Boolean?

Sample code:

package test;

import java.math.BigInteger;
import java.util.List;

import com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializer;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import com.orientechnologies.orient.object.serialization.OObjectSerializerContext;
import com.orientechnologies.orient.object.serialization.OObjectSerializerHelper;

public class HashmapIterationTest {
    public static void main(String[] args) throws Exception{
        Runner r = new Runner();
        r.run();
    }

public static class Runner{

    private OObjectDatabaseTx db;

    public void run() throws Exception{
        db = new OObjectDatabaseTx("plocal:c:/testodb");
        if(db.exists()){
            db.open("admin", "admin");
        }else{
            db.create();
        }

        //Hack for BigInteger
        OObjectSerializerContext serializerContext = new OObjectSerializerContext();
        serializerContext.bind(new OObjectSerializer<BigInteger, Long>() {
            public Long serializeFieldValue(Class<?> itype,  BigInteger iFieldValue) {
                return iFieldValue.longValue();
            }
            public  BigInteger unserializeFieldValue(Class<?> itype, Long iFieldValue) {
                return BigInteger.valueOf(iFieldValue);
            }
        });
        OObjectSerializerHelper.bindSerializerContext(null, serializerContext);

        db.getEntityManager().registerEntityClass(Parent.class);

        db.save(new Parent(5));

        List<Parent> result = db.query(new OSQLSynchQuery<Parent>("select from parent"));
        for(Parent p: result){
            System.out.println("Parent: " + p.getBigInt());
        }
    }
}

public static class Parent{
    BigInteger bigInt;
    public Parent(){
    }
    public Parent(int test){
        this.bigInt = BigInteger.valueOf(test);
    }
    public void setBigInt(BigInteger bigInt){
        this.bigInt = bigInt;
    }
    public BigInteger getBigInt(){
        return bigInt;
    }
    public String toString(){
        return "Parent: " + getBigInt();
    }
}

}

Maven dependencies for version info:

<dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orient-commons</artifactId>
        <version>1.5.1</version>
        <type>bundle</type>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-core</artifactId>
        <version>1.5.1</version>
        <type>bundle</type>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-object</artifactId>
        <version>1.5.1</version>
        <type>bundle</type>
    </dependency>

I got in touch with the guys on the OrientDB Google group and they answered this question for me, so I'll just leave this here for the sake of posterity.

The documentation I was reading was incorrect. BigInteger is not supported as a custom data type. Google Groups Discussion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM