I have been trying out object ox io for Java. It has been working well on Android hence I decided to go with it on Java desktop implementation.
The problem I am facing is that I can save my data at run time but when I restart the app or desktop app the data is gone, is forgotten, which is very strange. I have tried to look for an explanation but haven't found anything on this. Can anyone help or have an idea why this is? In the mean time I have reverted to using SQLite. The app is intended to be very big and have a lot of multi-threads.
here is a sample
import io.objectbox.BoxStore;
import io.objectbox.DebugFlags;
import lombok.SneakyThrows;
import java.io.File;
import java.io.IOException;
public class DBObjectManager {
public static DBObjectManager objectIOAccessInstance ;
private BoxStore store;
private DBObjectManager() {
File tempFile = null;
try {
tempFile = File.createTempFile("objectdb", "");
} catch (IOException e) {
e.printStackTrace();
}
tempFile.delete();
store = MyObjectBox.builder()
.directory(tempFile)
.debugFlags(DebugFlags.LOG_QUERIES | DebugFlags.LOG_QUERY_PARAMETERS)
.build();
}
public static DBObjectManager getinstance() {
if (objectIOAccessInstance == null) {
objectIOAccessInstance = new DBObjectManager();
}
return objectIOAccessInstance;
}
public BoxStore getStore() {
return store;
}
}
You are creating a new temporary file each time when you execute your application. I guess that explains your problem.
From the docs:
creates a new empty file in the specified directory. deleteOnExit() method is called to delete the file created by this method.