orientechnologies / spring-data-orientdb

OrientDB implementation for SpringData

Home Page:http://forum.springsource.org/showthread.php?99627-OrientDB-support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to store a HashMap of strings using orientdb object api?

anidotnet opened this issue · comments

I have a simple class as follows:

public class ConnectionAdapter {
    @Id
    private String id;

    @Version
    private Long version;

    private String name;
    private ProviderType providerType;

    private Map<String, String> properties = new ConcurrentHashMap<>();

    public ConnectionAdapter(ProviderType providerType) {
        this.providerType = providerType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ProviderType getProviderType() {
        return providerType;
    }

    public void setProviderType(ProviderType providerType) {
        this.providerType = providerType;
    }

    public void add(String name, String value) {
        properties.put(name, value);
    }

    public boolean containsKey(String name) {
        return properties.containsKey(name);
    }

    public Object getString(String name) {
        return properties.get(name);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}


public class TestAdapter extends ConnectionAdapter {
    public static final String EMAIL = "test.email";
    public static final String URL = "test.url";
    public static final String USER = "test.user";
    public static final String PASSWORD = "test.password";

    public TestAdapter() {
        super(ProviderType.ABC);
    }
}

I am trying to persist this TestAdapter object using orientdb object api. I am able to save it to the db, but when I try to fetch it, I am not getting anything in properties field. Other fields are having data, but map field is not having any data when retrieved.

TestAdapter testAdapter = new TestAdapter();
testAdapter.setName("XYZ");
testAdapter.add(TestAdapter.URL, "https://test.com");
testAdapter.add(TestAdapter.USER, "abcd");
testAdapter.add(TestAdapter.PASSWORD, "abcd");
testAdapter.add(TestAdapter.EMAIL, "abcd@test.com");

// IDE debugger shows testAdapter is having data here in properties field
String id = adapterRepository.save(testAdapter).getId();
        logger.info("Id generated - " + id);

        List<ConnectionAdapter> connectionAdapters = adapterRepository.findAll();
        connectionAdapters.forEach(adapter -> {
            assertEquals(adapter.getName(), name);
            logger.info("Retrieved connection name " + adapter.getName());
            // I am getting null here instead of "https://test.com. Why????
            logger.info("Retrieved connection server " + adapter.getString(TestAdapter.URL));
        });

So how to properly save and retrieve this data?